5.0.10 • Published 5 years ago

ih-black-lion v5.0.10

Weekly downloads
3
License
GPL-3.0
Repository
-
Last release
5 years ago

ih-black-lion

The core of your Ih project, BlackLion is the link between the front and backend of your project. It uses redux to store data and trigger changes within your app.

Redux uses a combination of Reducers and Actions to handle changes to state within an app.

Usage

You can use the default export of this module the same way you would use any redux store.

import BlackLion from 'ih-black-lion';
import { Provider } from 'react-redux';

React.render((
  <Provider store={BlackLion}>...</Provider>
), document.body);

From within a 'smart' component, you can dispatch actions. Actions generally follow this formula: someAction(Connector, requestParams, ...<other action specific parameters>)

Connector - it is strongly suggested that you use ih-ps-connector, or a fork of it, for this. It handles al communication with the database and does any modeling needed to format the response object.

requestParams - an object containing a url property that defines the endpoint url of the request, and other properties that might be necessary such as authorization and request headers.

Caching with black-lion

This module also provides a way to cache your stores state in another location by using the redux-persist library.

The following is an example of how to set up black-lion to cache its state.

import { initBlackLionCaching } from 'ih-black-lion';
import { Provider } from 'react-redux';

initBlackLionCaching(
  (blackLion, blackLionPersistor) => {
    React.render((
      <Provider store={blackLion}>...</Provider>
    ), document.body);
  },
  {
    skipRestore: true,
  }
);

initBlackLionCaching(cb, [config, finalCreateStore])

The cb takes two parameters: a created redux store using finalCreateStore or ih-black-lion's default createStore, and a persistor object created by redux-persist's persistStore function. If you want black-lion to rehydrate its state from the cache before your initial render then call React.render from within the callback. Otherwise your app will render and then attempt to rehydrate the state after the fact.

config is the same as the config object that you would pass to the persistStore function.

finalCreateStore allows you to pass in a custom createStore function if you don't want to use ih-black-lion's default middleware.

Reducers

Reducers handle the actual modification of the state given a specified action.

Reducer Documentation

Actions

Actions tell the Reducer what is going on so that it can modify the state appropriately.

Action Documentation

Further Reading

If you wish to learn more about Redux please help yourself to their documentation

Adding Services

  1. create actions in ./lib/actions/<ServiceName>Actions.js

  2. create a reducer in ./lib/reducers/<ServiceName>Reducer.js

  3. add <serviceName>State field to the reducer object in ./index.js with a value of the imported <ServiceName>Reducer.js file

  4. add <ServiceName>Actions field to the actions object in ./index.js with a value of the imported <ServiceName>Actions.js file

  5. add mock response data to the ./test/lib/mocks.js file and export them

  6. add a mock service call to the ./test/lib/Connector.js file that returns the mock data you just created

  7. create tests

  • there's a template for tests located at ./test/lib/test.template.js
  • copy and paste the template into a new file in the test directory and name it test<ServiceName>.js
  • refactor the template to match your service
  1. make sure all tests are still passing by running npm test

  2. add your name and email to the contributors field in package.json

  3. run npm version prerelease

  4. submit a pull-request to the master branch


See Also

5.0.10

5 years ago

5.0.9

5 years ago

5.0.8

5 years ago

5.0.7

5 years ago

5.0.6

5 years ago

5.0.5

5 years ago

5.0.4

5 years ago

5.0.3

5 years ago

5.0.2

5 years ago

5.0.1

5 years ago

5.0.0

6 years ago

4.0.0-alpha.12

6 years ago

4.0.0-alpha.11

6 years ago

4.0.0-alpha.10

6 years ago

4.0.0-alpha.9

6 years ago

4.0.0-alpha.8

6 years ago

4.0.0-alpha.7

6 years ago

4.0.0-alpha.6

6 years ago

4.0.0-alpha.5

6 years ago

4.0.0-alpha.4

6 years ago

4.0.0-alpha.3

6 years ago

4.0.0-alpha.2

6 years ago

4.0.0-alpha.1

6 years ago

3.0.33

6 years ago

3.0.32-alpha.1

7 years ago

3.0.32

7 years ago

3.0.31

7 years ago

3.0.30

7 years ago

3.0.29

7 years ago

3.0.28

7 years ago

3.0.27

7 years ago

3.0.26

7 years ago

3.0.25

7 years ago

3.0.24

7 years ago

3.0.16-alpha.2

7 years ago

3.0.23

7 years ago

3.0.16-alpha.1

7 years ago

3.0.22

7 years ago

3.0.21

7 years ago

3.0.20

7 years ago

3.0.19

7 years ago

3.0.18

7 years ago

3.0.17

7 years ago

3.0.16

7 years ago

3.0.15

7 years ago

3.0.14

7 years ago

3.0.13

7 years ago

3.0.12

7 years ago

3.0.11

7 years ago

3.0.10

7 years ago

3.0.9

7 years ago

3.0.8

7 years ago

3.0.7

7 years ago

3.0.6

7 years ago

3.0.5

7 years ago

3.0.4

7 years ago

3.0.3

7 years ago

3.0.2

7 years ago

3.0.1

7 years ago

3.0.0

7 years ago

2.5.0-alpha.26

7 years ago

2.5.0-alpha.25

7 years ago

2.5.0-alpha.24

7 years ago

2.5.0-alpha.23

7 years ago

2.5.0-alpha.22

7 years ago

2.5.0-alpha.21

7 years ago

2.5.0-alpha.20

7 years ago

2.5.0-alpha.19

7 years ago

2.5.0-alpha.18

7 years ago

2.5.0-alpha.17

7 years ago

2.5.0-alpha.16

7 years ago

2.5.0-alpha.15

7 years ago

2.5.0-alpha.14

7 years ago

2.5.0-alpha.13

7 years ago

2.5.0-alpha.12

7 years ago

2.5.0-alpha.11

7 years ago

2.5.0-alpha.10

7 years ago

2.5.0-alpha.9

7 years ago

2.5.0-alpha.8

7 years ago

2.5.0-alpha.7

7 years ago

2.5.0-alpha.6

7 years ago

2.5.0-alpha.5

7 years ago

2.5.0-alpha.4

7 years ago

2.5.0-alpha.3

7 years ago

2.5.0-alpha.1

7 years ago

2.4.3

7 years ago

2.4.2

7 years ago

2.4.1

8 years ago

2.5.0

8 years ago

2.4.0

8 years ago

2.3.1

8 years ago

2.3.0

8 years ago

2.3.0-5

8 years ago

2.3.0-4

8 years ago

2.3.0-3

8 years ago

2.3.0-2

8 years ago

2.3.0-1

8 years ago

2.3.0-0

8 years ago

2.2.6

8 years ago

2.2.5

8 years ago

2.2.5-3

8 years ago

2.2.5-2

8 years ago

2.2.5-1

8 years ago

2.2.5-0

8 years ago

2.2.4

8 years ago

2.2.3

8 years ago

2.2.2

8 years ago

2.2.1

8 years ago

2.2.0

8 years ago

2.2.0-12

8 years ago

2.2.0-11

8 years ago

2.2.0-10

8 years ago

2.2.0-9

8 years ago

2.2.0-8

8 years ago

2.2.0-7

8 years ago

2.2.0-6

8 years ago

2.2.0-5

8 years ago

2.2.0-4

8 years ago

2.2.0-3

8 years ago

2.2.0-2

8 years ago

2.2.0-1

8 years ago

2.2.0-0

8 years ago

2.1.0-0

8 years ago

2.0.0

9 years ago

1.2.7

9 years ago

1.2.6-rc2

9 years ago

1.2.6-rc1

9 years ago

1.2.5

9 years ago

1.2.4

9 years ago

1.2.3

9 years ago

1.2.2-alpha.4

9 years ago

1.2.2-alpha.3

9 years ago

1.2.2-alpha.1

9 years ago

1.2.2

9 years ago

1.2.1

9 years ago

1.2.0

9 years ago