Point One - Is a powerful implementation of Flux/Redux to start your application with easy
point-one is an state container for any kind of application. It can be used on client and server sides. It's built with a lot of ready to use helpers and extenders.
**Example skeleton appliation from creator: Isomorphic Todo
Installation
npm install point-one --save
Stores
point-one not require to use only one store for application but for comfortable development please make independent stores only when you have some big scopes with a lot of reducers that can decrease performance of application
/** * this reducer provide structure and default values: * { * auth: { * authenticated: false, * error: false, * identity: null * }, * notifications: { * counter: 0 * } * } */const reducer = const store = store//getState will return current state of storeconsole//We dispatch event with type 'AUTH_SUCCESS' and some data. type field is requiredstore
This is not real-world example but as you can see, we make a lot of work with authentication and even with notifications. So when something dispatch authentication event 'AUTH_SUCCESS' we anytime know what part of our store will change, and also we understand how it should be.
In example code we use two helpers from point-one: concatReducers
and concatEventReducers
:
concatReducers
- is useful to make independent reducers for each field inside object So your reducers will be more readable
concatEventReducers
- is useful to make more readable reducers for field to see event => action without a lot of code inside switch-cases
Thunk
point-one store have built-in thunk functionality but if you use any of extenders please attach thunk dispatcher to not write strange checks for event as a function that repeats thunk.
Actions
Actions is a simple function that produce some event that can be used for dispatching. Event must be a plain object and contains type variable or be a function that will receive dispatcher for async things. Functionality of dispatcher can be extended by composition.
Example of actions:
{ return type: TODO_CREATE value } { return }
Reducers
Reducer is a function that based on some Event make new state. For example you can read about Array.reduce
Simple example of reducer
{ } var someState = 0;someState = //1someState = //0someState = //0
Built-in utils
listen
listen is an decorator for React Components that will provide some data from store to your Component state like connect from react-redux
{ e thisactions } { if thisstateauthenticated return <div> You are already authenticated </div> return <form className="login-form" onSubmit= this> <div className="form-error" hidden=!!thisstateerror> thisstateerror </div> ...fields </form> } LoginForm
This is really simple component but as you can see you don't need to write code for sync state between store and component
Syntax: