Code Monkey home page Code Monkey logo

Comments (4)

0xkee avatar 0xkee commented on August 11, 2024

看起来像是 immer 的报错,什么场景出现的?

from stook.

arvinxx avatar arvinxx commented on August 11, 2024

看起来像是 immer 的报错,什么场景出现的?

  1. 定义了一个 config
  const [dataSourceConfig] = useStore('dataSourceConfig', res);

config 里是一个对象变量

对外暴露的修改方式 我是直接返回对象的

handleTableDataSourceConfig: (value) => {
      mutate('dataSourceConfig', (state: ProtableDataSourceState) => {
        return { ...state, ...value };
      });
    },

源码在这:https://github.com/arvinxx/components-editor-test/blob/master/src/models/dataSource.ts#L90

这个项目是一个 ProTable 编辑器,之前在业务里用了 dva。近期准备抽出来组件化并开源,所以需要脱离 dva。
在找数据流解决方案的时候看到你的项目来着,感觉用起来还可以,赞一下。

from stook.

0xkee avatar 0xkee commented on August 11, 2024

不清楚value是什么类型,如果是一个复杂类型是不是可能有什么意外,你先改成这样试试?

handleTableDataSourceConfig: (value) => {
  const state = getState('dataSourceConfig')
  mutate('dataSourceConfig', { ...state, ...value })
},

from stook.

0xkee avatar 0xkee commented on August 11, 2024

mutate 的核心代码如下,不知道你这个在哪步报错了:

  private getNextState(value: any): any {
    let nextState: any

    // not function
    if (typeof value !== 'function') return value

    // can not use immer
    if (typeof this.state !== 'object') return value(this.state)

    let useImmer = true

    const immerState = produce(this.state, draft => {
      const fnValue = value(draft)

      // use function return value
      if (fnValue && typeof fnValue === 'object') {
        nextState = fnValue
        useImmer = false
      }
    })

    if (useImmer) {
      nextState = immerState
    }

    return nextState
  }

from stook.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.