我不在是我

文章 评论 浏览 28

我不在是我 2025-02-13 09:11:49

我建议使用 enum 为此:

types.d.ts

export enum PluginNames {
   PluginA = 'pluginA',
   PluginB = 'pluginB',
   PluginC = 'pluginC',
}

interface Plugin {
   name: PluginNames
}

src/plugins/plugina/index.ts.ts

const pluginA: Plugin = {
  name: PluginNames.PluginA
}

export default pluginA

src/plugins/ index.ts

import pluginA from "./pluginA"
import pluginB from "./pluginB"
...

export default {
  [PluginNames.PluginA]: pluginA
  [PluginNames.PluginB]: pluginB
  ...
}

您也可以使用类型工会进行相同的操作:

interface Plugin {
   name: 'pluginA' | 'pluginB' | 'pluginC'
}

I would suggest using enum for that:

types.d.ts

export enum PluginNames {
   PluginA = 'pluginA',
   PluginB = 'pluginB',
   PluginC = 'pluginC',
}

interface Plugin {
   name: PluginNames
}

src/plugins/pluginA/index.ts

const pluginA: Plugin = {
  name: PluginNames.PluginA
}

export default pluginA

src/plugins/index.ts

import pluginA from "./pluginA"
import pluginB from "./pluginB"
...

export default {
  [PluginNames.PluginA]: pluginA
  [PluginNames.PluginB]: pluginB
  ...
}

You can also do the same using type unions:

interface Plugin {
   name: 'pluginA' | 'pluginB' | 'pluginC'
}

如何在打字稿中推断计算的对象键

我不在是我 2025-02-13 04:47:42

我在 Android flag_secure

只是出于好奇:您如何允许屏幕屏幕拍摄而不屏幕录制?

I don't see any option in flutter_window_manager that would allow to distinguish between screen recording and screenshots. The underlying Android functionality also behaves the same, that is screenshot&recording aren't allowed see Android FLAG_SECURE

Just out of curiosity: How come you allow screen shots but not screen recording?

如何仅通过flutter禁用Android和iOS中的屏幕录制(而不是屏幕截图)?

我不在是我 2025-02-12 20:18:15

首先,您创建发布数据的动作,然后发送数据

export const postData = createAsyncThunk(
  "type/postData",
  async (data) => {
    try {
      const response = await axios.post("https://reqres.in/api/users", data);
      // If you want to get something back
      return response.data;
    } catch (err) {
      console.error(err)
    }
  }
);

然后在要发送数据的地方,只需使用 data 参数,发送:

const handlePost = () => {
  // whatever you want to send
  const data = .........
  
  dispatch(postData(data));
}

如果您愿意,也可以为此操作修改 extrareducer

First you create the action of posting data and send the data:

export const postData = createAsyncThunk(
  "type/postData",
  async (data) => {
    try {
      const response = await axios.post("https://reqres.in/api/users", data);
      // If you want to get something back
      return response.data;
    } catch (err) {
      console.error(err)
    }
  }
);

Then in a place where you want to send that data you just dispatch this action with the data argument that you want to send:

const handlePost = () => {
  // whatever you want to send
  const data = .........
  
  dispatch(postData(data));
}

If you want, you can also modify your extraReducers for this action.

如何使用redux thunk和redux工具包提出发布请求

我不在是我 2025-02-11 14:51:52

看看

简短,更新以匹配以下内容:

const App = () => {
  return (
    <Router>
      <Routes>
        <Route path="/" element={<Master />} />
        <Route path="/days" element={<Appone />} />
      </Routes>
    </Router>
  );
};

Take a look to https://reactrouter.com/docs/en/v6/upgrading/v5#relative-routes-and-links

Short, update to match this:

const App = () => {
  return (
    <Router>
      <Routes>
        <Route path="/" element={<Master />} />
        <Route path="/days" element={<Appone />} />
      </Routes>
    </Router>
  );
};

我正在面对React-Router-Dom的问题

我不在是我 2025-02-11 07:55:09
if(context.mounted)
    Navigator.push(
          context,
          PageTransition(
              type: PageTransitionType.rightToLeft,
              child: const ResetEmailScreen()
          )
    );
if(context.mounted)
    Navigator.push(
          context,
          PageTransition(
              type: PageTransitionType.rightToLeft,
              child: const ResetEmailScreen()
          )
    );

请勿在异步差距上使用buildContexts。在更新Pub yaml之后

我不在是我 2025-02-11 04:36:53

参数是按值传递的,除非函数签名另有指定:

  • in void foo(type arg) arg arg 都按值传递,无论 type> type> type> type 是一种简单的类型,一种指针类型或类型类型,
  • void foo(type&amp; arg) arg 通过参考将传递。

如果存在数组,则传递的值是指向数组的第一个元素的指针。如果您知道编译时数组的大小,则也可以通过参考传递数组: void foo(type(&amp; arg)[10] [10])

Arguments are passed by value, unless the function signature specifies otherwise:

  • in void foo(type arg), arg is passed by value regardless of whether type is a simple type, a pointer type or a class type,
  • in void foo(type& arg), arg is passed by reference.

In case of arrays, the value that is passed is a pointer to the first element of the array. If you know the size of the array at compile time, you can pass an array by reference as well: void foo(type (&arg)[10]).

c&#x2b;&#x2b;按值或参考传递对象?

我不在是我 2025-02-11 03:37:53

我找到了解决方案:

alphaNumeric=({L}+|{L}+{D}+)+
email={alphaNumeric}"@"{alphaNumeric}"."({L}+|{L}+"."{L}+)

这是正则表达式

I found the solution:

alphaNumeric=({L}+|{L}+{D}+)+
email={alphaNumeric}"@"{alphaNumeric}"."({L}+|{L}+"."{L}+)

This is the regular expression

flex中电子邮件的正则表达式

我不在是我 2025-02-10 23:39:16

@netwave专注于该怎么做,我想解释为什么

有两个问题:实施问题和设计问题。

实现问题是通过引起ICE的仿制物的编译(内部编译器错误,编译器的崩溃)的各种错误(很多)错误,我认为甚至误解和健全问题。

设计问题更有问题:此表达不像那样微不足道。如果溢出怎么办?

在某种情况下,常数表达式溢出,我们。溢出只是一个考虑因素:有很多原因可能导致表达式无法编译(例如,数组太大或访问范围)。当常数不通用时,很容易拒绝它们。但是,使用通用常数这样做要困难得多。我们有两个选择:

第一个是像C ++。也就是说,如果实际上发生发生,则允许编译和错误,就像C ++对其模板一样。

问题在于,Rust在一般情况下故意选择了不是 ,并且与特质界限的方法一样,即要求代码能够将其编译为通用,而不是单态化时要求它编译。这是有充分理由的原因:变性后错误确实很严重(例如C ++),并且类型检查这很昂贵 - 货物检查不在后验证后错误上保释,只有 货物构建。这可能导致货物构建失败了为什么货物检查成功,那真的很糟糕。我们已经有一些变频器后错误,实际上这就是它们发生的事情:

trait Trait {
    const MAY_FAIL: u8;
}
struct S<const BASE: u8>;
impl<const BASE: u8> Trait for S<BASE> {
    const MAY_FAIL: u8 = BASE + 1;
}

fn cause_post_mono_error<T: Trait>() {
    _ = T::MAY_FAIL;
}

fn main() {
    // This will pass `cargo check`, but fail `cargo build`!
    cause_post_mono_error::<S<255>>();
}

第二种方法,这是 gen> generic_const_exprs 今天使用的方法是需要在签名中未能重复的每个表达式。我们通过这样做获得了两件事:

  1. 我们只能检查签名,因此在呼叫网站上我们知道此表达式将失败 - 它不满足要求。
  2. 添加一个可能失败的功能主体的表达,这是一个破坏的变化,必须反映在签名上 - 这是很好的,因为Rust的哲学是 每个破裂的变化都必须反映在签名上。这样可以防止诸如C ++之类的危险,即使使用广泛的测试套件,您也永远无法确定某些更改不会给某些客户带来一些变化。

问题是,需要重复签名中的每个表达式,ah,重复。并不明显。因此,我们仍在寻求想法(这是一个)。而且我们无法稳定 generic_const_exprs 设计问题实现问题。

@Netwave focused on what to do, I want to explain why.

There are two problems with this: implementation problems and design problems.

The implementation problems are various (lots of) bugs with the compilation of such generics that cause ICEs (Internal Compiler Errors, a crash of the compiler) and I think even miscompilations and soundness issues.

The design problem is more problematic: this expression is not as trivial as it seems. What if it overflows?

In a case a constant expression overflows we display an error. Overflow is just one consideration: there are many reasons that can cause an expression to fail to compile (for example, array too big, or access out of bounds). It is easy to reject them when the constant is not generic; but doing so with a generic constant is much harder. We have two choices:

The first is to be like C++. That is, allow that to compile and error if it is actually gets happen, like C++ does with its templates.

The problem with that is that Rust chose deliberately to not be like C++ in the general case, and went with the approach of trait bounds, that is, require the code to be able to compile as generic, instead of requiring it to compile when monomorphized. And this is for very good reasons: post-monomorphization errors are really bad (like C++), and type-checking this is expensive - cargo check does not bail on post-monomorhpization errors, only cargo build. That can cause cargo build to fail why cargo check succeeds, and that is really bad. We already have some post-monomorphization errors, and indeed this is what happens to them:

trait Trait {
    const MAY_FAIL: u8;
}
struct S<const BASE: u8>;
impl<const BASE: u8> Trait for S<BASE> {
    const MAY_FAIL: u8 = BASE + 1;
}

fn cause_post_mono_error<T: Trait>() {
    _ = T::MAY_FAIL;
}

fn main() {
    // This will pass `cargo check`, but fail `cargo build`!
    cause_post_mono_error::<S<255>>();
}

The second approach, which is what generic_const_exprs uses today, is to require every expression that may fail to be repeated in the signature. We earn two things by doing that:

  1. We can check only the signature, and thus at the call site we know this expression will fail - it doesn't satisfy the requirements.
  2. Adding an expression that can fail to the function body, which is a breaking change, is required to be reflected on the signature - and this is good, because Rust's philosophy is that every breaking change has to be reflected on the signature. This prevents hazards like in C++, where even with an extensive test suite you can never be sure some change didn't break something to some customer.

Problem is, requiring to repeat every expression in the signature is, ah, repetitive. And not obvious. So we are still seeking for ideas (here is one). And we cannot stabilize generic_const_exprs until both the design issues and the implementation issues are settled.

为什么生锈只允许独立的数组大小常数?

我不在是我 2025-02-10 18:55:40

要使用 fetch 将URL参数添加到请求中,您需要将它们附加到fetch url(还设置了正确的标题名称):

const params = new URLSearchParams({ name });

if (this.customLookupAddress) {
  params.set('lookup', this.customLookupAddress);
}
if (this.customGatewayAddress) {
  params.set('gateway', this.customGatewayAddress);
}
fetch(`${targetUrl}?${params}`, { headers: { 'Accept': 'application/json' } })
  .then(res => res.json())
  // ...

To add URL params to a request using fetch, you need to append them to the fetch url (and also set the correct header names):

const params = new URLSearchParams({ name });

if (this.customLookupAddress) {
  params.set('lookup', this.customLookupAddress);
}
if (this.customGatewayAddress) {
  params.set('gateway', this.customGatewayAddress);
}
fetch(`${targetUrl}?${params}`, { headers: { 'Accept': 'application/json' } })
  .then(res => res.json())
  // ...

使用Fetch API传递参数

我不在是我 2025-02-09 18:47:25

如果您假设所有“子阵列”均来自相同的长度,则可以进行基本迭代,如下所示:

double[][] newAllArray = new double[allArray.length()][allArray.getJSONArray(0).length()];
for (int i = 0; i < allArray.length(); i++) {
  for (int j = 0; j < allArray.getJSONArray(i).length(); j++) {
    double originalValue = allArray.getJSONArray(i).getDouble(j);
    newAllArray[i][j] = originalValue;
  }
}

If you assume that all 'sub-arrays' are from the same length, you can do a basic iteration as follows:

double[][] newAllArray = new double[allArray.length()][allArray.getJSONArray(0).length()];
for (int i = 0; i < allArray.length(); i++) {
  for (int j = 0; j < allArray.getJSONArray(i).length(); j++) {
    double originalValue = allArray.getJSONArray(i).getDouble(j);
    newAllArray[i][j] = originalValue;
  }
}

将双重价值的jsonarray转换为2维双阵列

我不在是我 2025-02-08 18:26:03

您不能使用等待使用它的方式。 等待应仅在 async 函数内使用。

尝试以下操作:

async function a(){
        return 'a';
    }
    console.log(a());

You can't use await the way you are using it. await should be only used inside of an async function.

try this:

async function a(){
        return 'a';
    }
    console.log(a());

JavaScript意外标识符,但在控制台中起作用

我不在是我 2025-02-08 04:43:05

您不能使用 strendot 做到这一点,因为那是一个图形函数。但是您可以使用 kdeplot 并提供轴对象:

ax = plt.axes()
sns.kdeplot(SD_frame_A, ax=ax)
sns.kdeplot(SD_frame_S, ax=ax)
sns.kdeplot(SD_frame_D, ax=ax)
plt.show()

You can't do that with displot because that is a figure-level function. But you can use kdeplot and provide an axes object:

ax = plt.axes()
sns.kdeplot(SD_frame_A, ax=ax)
sns.kdeplot(SD_frame_S, ax=ax)
sns.kdeplot(SD_frame_D, ax=ax)
plt.show()

如何与Seaborn绘制多个分销图?

我不在是我 2025-02-07 13:45:16

首先,按钮已经具有您可以使用的图像视图,因此请不要这样做:

[btn addSubview:imgArrow];

相反,请执行此操作:

[btn setImage:[UIImage imageNamed:@"arrow.jpeg"] forState:UIControlStateNormal];

然后,在您的 section> sectionOpentoggle method(假设它看起来像这样),请更改图像:

- (void)sectionOpenToggle:(UIButton *)sender {
    [sender setImage:[UIImage imageNamed:@"other-arrow.jpeg"] forState:UIControlStateNormal];
    // whatever else you want to do
}

First, buttons already have an image view that you can use, so don't do this:

[btn addSubview:imgArrow];

Instead, do this:

[btn setImage:[UIImage imageNamed:@"arrow.jpeg"] forState:UIControlStateNormal];

Then, in your sectionOpenToggle method (assuming it looks like this), change the image:

- (void)sectionOpenToggle:(UIButton *)sender {
    [sender setImage:[UIImage imageNamed:@"other-arrow.jpeg"] forState:UIControlStateNormal];
    // whatever else you want to do
}

在单击时,如何更改tableView标头按钮图像。需要目标C中的代码

我不在是我 2025-02-07 11:47:44

您可以通过终端操作 collect(collectors.tomap())将每个学生的ID映射,然后处理碰撞案例以将您的不同学生实例合并为新的实例。

到那时,在启用新的学生时,您可以实现嵌套流以合并两个碰撞实例的标记。通过应用第二个 collect(collectors.tomap()),您可以按主题ID进行分组,然后通过合并标记的值再次处理碰撞案例。

在下面的摘要中,我通过添加第二个 student 来丰富您的测试用例:

List<Student> list = new ArrayList<>(List.of(
        new Student(1, new ArrayList<>(List.of(new Marks(1, 10), new Marks(2, 10)))),
        new Student(1, new ArrayList<>(List.of(new Marks(1, 15), new Marks(3, 10)))),
        new Student(2, new ArrayList<>(List.of(new Marks(1, 5), new Marks(2, 10)))),
        new Student(2, new ArrayList<>(List.of(new Marks(2, 5), new Marks(3, 10))))
));

//Temporary map
Map<Integer, Student> mapTemp = list.stream()
        .collect(Collectors.toMap(Student::getStudentId,                                        //grouping by student id
                Function.identity(),                                                            //setting as value the student
                (s1, s2) -> new Student(s1.getStudentId(), new ArrayList<>(                     //Creating a new Student whose list of marks is given by the merged marks of the two colliding students
                        Stream.concat(s1.getMarkList().stream(), s2.getMarkList().stream())     //Chaining the two lists of marks into a single stream
                                .collect(Collectors.toMap(Marks::getSubjectId,                  //Grouping by the marks by the subject id
                                        Function.identity(),                                    //Setting as value the mark
                                        (m1, m2) -> new Marks(m1.getSubjectId(), m1.getMark() + m2.getMark())))  //Handling the colliding marks by summing them together
                                .values())))                                                    //Retrieving the collection of merged marks
        );

//Result list with the merged students
List listRes = new ArrayList(mapTemp.values());
System.out.println(listRes);

这里还有一个链接来测试上面的代码:

https://ideone.com/0i6zqg

You could map each student by their id with the terminal operation collect(Collectors.toMap()), then handling the collision cases to merge your different instances of student into a new one.

At that point, when instancing a new Student, you could implement a nested stream to merge the marks of the two colliding instances. By applying a second collect(Collectors.toMap()), you could group the marks by the subject id and then handling once again the colliding cases by merging the marks' value.

In the snippet below, I've enriched your test case by adding a second Student:

List<Student> list = new ArrayList<>(List.of(
        new Student(1, new ArrayList<>(List.of(new Marks(1, 10), new Marks(2, 10)))),
        new Student(1, new ArrayList<>(List.of(new Marks(1, 15), new Marks(3, 10)))),
        new Student(2, new ArrayList<>(List.of(new Marks(1, 5), new Marks(2, 10)))),
        new Student(2, new ArrayList<>(List.of(new Marks(2, 5), new Marks(3, 10))))
));

//Temporary map
Map<Integer, Student> mapTemp = list.stream()
        .collect(Collectors.toMap(Student::getStudentId,                                        //grouping by student id
                Function.identity(),                                                            //setting as value the student
                (s1, s2) -> new Student(s1.getStudentId(), new ArrayList<>(                     //Creating a new Student whose list of marks is given by the merged marks of the two colliding students
                        Stream.concat(s1.getMarkList().stream(), s2.getMarkList().stream())     //Chaining the two lists of marks into a single stream
                                .collect(Collectors.toMap(Marks::getSubjectId,                  //Grouping by the marks by the subject id
                                        Function.identity(),                                    //Setting as value the mark
                                        (m1, m2) -> new Marks(m1.getSubjectId(), m1.getMark() + m2.getMark())))  //Handling the colliding marks by summing them together
                                .values())))                                                    //Retrieving the collection of merged marks
        );

//Result list with the merged students
List listRes = new ArrayList(mapTemp.values());
System.out.println(listRes);

Here there is also a link to test the code above:

https://ideone.com/0i6ZqG

Java 8,合并两个或多个嵌套列表

我不在是我 2025-02-07 08:51:14

通常, usememo 用于缓存重新订阅者之间计算的结果;似乎这更适合您的情况,因为您正在调用 renderfooter 并将其结果作为道具传递。

请注意,还可以使用 usememo 进行优化渲染,在 docs

function Parent({ a, b }) {
  // Only re-rendered if `a` changes:
  const child1 = useMemo(() => <Child1 a={a} />, [a]);
  // Only re-rendered if `b` changes:
  const child2 = useMemo(() => <Child2 b={b} />, [b]);
  return (
    <>
      {child1}
      {child2}
    </>
  )
}

之所以在这里起作用的原因可能是由于以下事实:在重新渲染期间,react 看到对相同的反应元素的引用放置在组件层次结构中,它跳过重新渲染它。这发生在此处是因为通过使用 usememo 来创建 child1 child2 elements,我们确保在随后的渲染中返回相同的元素参考它的依赖性没有改变。

USECALLBACK 使您可以缓存功能定义。

In general useMemo is used to cache the result of a calculation between re-renders; seems that is more appropriate for your case because you are calling renderFooter and passing its result as props.

Note there is also a possibility to optimize rendering using useMemo, it is highlighted in the docs:

function Parent({ a, b }) {
  // Only re-rendered if `a` changes:
  const child1 = useMemo(() => <Child1 a={a} />, [a]);
  // Only re-rendered if `b` changes:
  const child2 = useMemo(() => <Child2 b={b} />, [b]);
  return (
    <>
      {child1}
      {child2}
    </>
  )
}

The reason why it works here is probably due to the fact that when during a re-render, react sees reference to the same react element in the same place in component hierarchy, it skips re-rendering it. This happens here because by using useMemo to create child1 and child2 elements, we ensure that the same element reference is returned on subsequent renders as long as its dependencies have not changed.

useCallback lets you cache a function definition.

REACT- usecallback vs usememo for jsx元素

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文