3.2.0 • Published 5 years ago

redux-register v3.2.0

Weekly downloads
164
License
MIT
Repository
github
Last release
5 years ago

Redux Register

This document is for v5, for old versions is here .

Redux Register created in 2015, There was a problem that how to split code when use redux then, and redux-toolkit have not created. now Redux Register included some awesome features from redux-toolkit and react-react.

Namespace, the core concept

The core concet in Redux Register is namespace. the namespace is a tree like in LDAP.

                ROOT
                 |
                 |
        ---------------------
        |                    |
      BRANCH                LEAF
        |
   ------------
   |           |
  LEAF        LEAF

Leaves can store state, branches can not. for example:

import {register} from 'redux-register';

register('page.one', {});

// ✅ It's ok
register('page.two', {});

// ✅ It's ok
register('metadata', {});

// ❌ Can't do this, page.one is a branch now.
register('page.one.module', {});

Server Side Rendering

Redux Register v5 make SSR painless. You can define getServerState method when registering namespace:

import {register} from 'redux-register';

register('page.one', {
    initialState: {
        list: []
    },

    async getServerState({request}) {
        // Query database or fetch API
        // then return state.
        return ['state', 'from', 'server'];
    }
});

Then you can use collectServerState function create a initial state object from all namspaces that define getServerState:

import {collectServerState} from 'redux-register/serverstate';

// {
//     page: {
//         one: {
//             list: ['state', 'from', 'server']
//         }
//     }
// }
console.log(await collectServerState({request: 'http request object'}));

collectServerState function will perform all getServerState method in the whole app. It will bring negative impact. for example, a online shop website, register products list and product details namespace, the home page only need products list state, but the product details state also created from database. There is a performance problem. We can use ServerState object resolve this.

import {ServerState} from 'redux-register/serverstate';

var serverState = new ServerState();

// collect which namespaces used (by useStore hook) in HomePage.
serverState.collectNamespaces(<HomePage />);

console.log(await serverState.collectState(parameter));

Examples

More examples check here

6.3.0

1 year ago

6.1.0

1 year ago

6.0.3

2 years ago

6.2.0

1 year ago

6.1.1

1 year ago

6.0.2

2 years ago

6.0.1

2 years ago

6.0.0

2 years ago

5.6.0

2 years ago

5.5.0

2 years ago

5.4.0

2 years ago

5.3.0

2 years ago

5.2.0

2 years ago

5.1.0

2 years ago

5.0.0

3 years ago

5.10.0

2 years ago

5.0.0-rc.1

3 years ago

5.0.0-rc.2

3 years ago

5.0.0-rc.3

3 years ago

5.0.0-rc.4

3 years ago

5.0.0-rc.5

3 years ago

5.0.0-rc.7

3 years ago

5.0.0-rc.8

3 years ago

5.9.0

2 years ago

5.8.0

2 years ago

5.7.0

2 years ago

4.0.1

3 years ago

4.0.2

3 years ago

4.0.0

4 years ago

3.2.0

5 years ago

3.1.0

6 years ago

3.0.0

6 years ago

2.0.0

6 years ago

1.0.0

7 years ago

0.0.2

10 years ago

0.0.1

10 years ago