byte-fe / react-model

The next generation state management library for React
235 stars 22 forks source link

[Question] Is it possible to pass the 'NextModel' error if not using TypeScript? #108

Closed connor-odoherty closed 4 years ago

connor-odoherty commented 5 years ago

Upon startup, I always see an error along the lines of "We recommend you to use NextModel now...".

Is this just a 'type' error? As in, does it warn if a model is not defined as the NextModel type?

And if so, is it possible to avoid that error if not using TypeScript?

ArrayZoneYour commented 5 years ago

Welcome to your feedback : )

The type is the schema of model.

You will see the warning if using the old schema whether you are using TypeScript.

In order to avoid the warning, you should use the new schema of model:

const model = {
  actions: {
    // The order of params change
    increment: async (payload, { state, actions }) => {
      return {
        counter: state.counter + (params || 1)
      }
    },
  },
  state: initialState
}

// You need to wrap Model when export
export default Model(model)

TodoMVC Demo

ArrayZoneYour commented 4 years ago

Close the issue because the console.warn has been removed in v3.0.0 : )