Skip to content

Latest commit

 

History

History
80 lines (59 loc) · 3 KB

FAQ.md

File metadata and controls

80 lines (59 loc) · 3 KB

🏠 Home

Dynadux - FAQ

What is a Dynadux Store

Dynadux Store is the return of the createStore read here for more and is an object with two props: state getter and dispatch function.

How many states have a Dynadux Store

One.

If you come from Redux, in Redux, we have A Store with multiple States (root properties). In Dynadux, we have one Store, with one State, and the root props would be considered App's Section States.

What is Business Store

It is the return of a function that wraps a Dynadux store. The return has getters and methods to be used by the application. These getters and methods are accessing the Dynadux store.

You develop business Stores. Dynadux is the state manager, the engine, of these stores.

The Business Stores concept introduced by Dynadux's approach in this repo.

Does Dynadux have React Provider?

Since v2.2.0 it has, checkout the react-dynadux.

Provider promotes one State Management that makes the app a monolithic.

On the other hand, it offers some nice features for small or large react applications

  • Any component can be connected without pass the store directly
  • Reduces the global renderings since it renders only the connected components
  • No need to forceUpdate() onChange

With react-dynadux, there are some more benefits

  • It "publishes" any App Store and not the state
  • On component's connection, there is a callback to control the render according to the dispatched action & payload

How to dispatch through a reducer

reducers: {
  [actions.LOGIN]: ({dispatch, payload: {name, psw} }) => {
    loginUser(name, psw) // <- your async method
      .then(info => dispatch(actions.LOGIN_SUCCESS))
      .catch(error => dispatch(actions.LOGIN_DAILED, error));
  },
},

Or in modern async way

reducers: {
  [actions.LOGIN]: ({dispatch, payload: {name, psw} }) => {
    (async () => {  // make an async closure to use the await
      try {
        await loginUser(name, psw);
        dispatch(actions.LOGIN_SUCCESS);
      } catch(error) {
        dispatch(actions.LOGIN_DAILED, error);
      }
    })();
  },
},

_Personal preference the ().then().catch() pattern looks simpler!…

Read more