Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Realt is a new way to work with Redux inspired by Alt

License

NotificationsYou must be signed in to change notification settings

i-kitaev/realt

Repository files navigation

npm version

Realt is a new way to work withRedux inspired byAlt

If you want to skip the docs and jump straight to the code, you should check out /examples folder, there you'll find some of Redux examples migrated to realt

Getting Started

Install

npm install --save realt

Actions

createAction(actionName: string)
createAction(actionName: string, payloadCreator: function)
createAction(actionName: string, namespace: string)
createAction(actionName: string, payloadCreator: function, namespace: string)
createActions(Actions: object|array|function)
createActions(Actions: object|array|function, namespace: string)

Examples

Create single action
import{createAction}from'realt';constaddText=createAction('addText');expect(addText.toString()).toEqual('ADD_TEXT');expect(addText('Hello world')).toEqual({type:'ADD_TEXT',payload:'Hello world'});
Create from array
import{createActions}from'realt';constactions=createActions(['create','delete']);
Create from object
import{createActions}from'realt';constactions=createActions({create(id){returnid;},update(id,data){return{ id, data}}});
Create from class
import{createActions}from'realt';classActions{constructor(){this.generate('create');}update(id,data){return{ id, data};}}constactions=createActions(Actions);
ActionsClass.generate(…actionNames: string)

You can use this method in ActionsClass constructor, it'll setup actions which simply pass forward all incoming data

Note: all of the generated actions will receive only 1 parameter, so your data should be wrapped in an object

Reducer

createReducer(Reducer: object|function)
createReducer(Reducer: object|function, initialState: any)
createReducer(Reducer: object|function, namespace: string)
createReducer(Reducer: object|function, initialState: any, namespace: string)

Examples

Create from object
import{createReducer}from'realt';constinitialState=[{id:0,title:'Use Realt',}];constreducer=createReducer({create(state,id){// or handleCreate/reducerForCreate},update(state,id){// or handleUpdate/reducerForUpdate}},initialState);
Create from class
import{createReducer}from'realt';importactionsfrom'../actions';classReducer{constructor(){this.bindAction(actions.create,this.handleCreate);this.bindHandler(this.handleDelete,actions.delete);}getinitialState(){return[{id:0,title:'Use Realt',}];}handleCreate(state,id){returnstate.concat({ id,title:'New entity'});}handleDelete(state,id){returnstate.filter(entity=>entity.id!==id);}}exportdefaultcreateReducer(Reducer);
ReducerClass.initialState

Here you must bring an initial snapshot of your view's state

ReducerClass.bindHandler(reducerHandler: function, actionCreator: object)
ReducerClass.bindAction(actionCreator: object, reducerHandler: function)

This method is a bridge between your reducer and certain action type.When you call it, you're connecting the data flow from some action right into the store

About

Realt is a new way to work with Redux inspired by Alt

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp