Wener Notes

mutative

约 1 分钟阅读
  • unadlib/mutativeGitHubunadlib/mutativeunadlib/mutative · MIT, TS · 类似于 immer · 默认不 freeze · 使用重放的机制 - 性能更好 · shallow copy · 暴露更多内部可配置功能 - 更高的定制化能力 · 没有全局配置 · 支持 async笔记:mutative
    • MIT, TS
    • 类似于 immer笔记immerimmerjs/immer · 参考 · https://immerjs.github.io/immer/performance/ · 不支持的场景 https://github.com/unadlib/mutative/blob/main/test/immer-non-support.test.ts打开:/notes/web/react/immer
      • 默认不 freeze
      • 使用重放的机制 - 性能更好
        • shallow copy
      • 暴露更多内部可配置功能 - 更高的定制化能力
      • 没有全局配置
      • 支持 async
      • 使用 json patch

Notes

  • markSimpleObject
TypeScript
export const markSimpleObject = (value: unknown) => {
  if (isSimpleObject(value)) {
    return dataTypes.immutable;
  }
  return;
};

const isSimpleObject = (value: unknown) => {
  if (!value || typeof value !== 'object') return false;
  const prototype = Object.getPrototypeOf(value);
  if (prototype === null) {
    return true;
  }
  const constructor = Object.hasOwnProperty.call(prototype, 'constructor') && prototype.constructor;

  if (constructor === Object) return true;

  return typeof constructor === 'function' && Function.toString.call(constructor) === constructorString;
};

关联信息

反向链接、本文链接的其他页面和外部资料。

站内链接

  • immer
    笔记 · immer

    immerjs/immer · 参考 · https://immerjs.github.io/immer/performance/ · 不支持的场景 https://github.com/unadlib/mutative/blob/main/test/immer-non-support.test.ts

References

GitHub1 条
最近更新commit 3124bebEdit

On this page