rigby
v1.5.2
Published
A micro library for managing state with React.
Downloads
157
Readme
rigby
React is great, but... y'know
Installation
Creating a Store
Rigby.createStore('YourStoreName', {
state: {
todos: [
{
text: 'Your Data Goes Here',
complete: false
}
]
},
actions: {
addTodo: function(text, complete) {
this.state.todos.push({ text: text, complete: complete });
this.emitChange();
}
}
});
Or with ES2015+:
import Store from "rigby";
class YourStore extends Store {
constructor() {
super("YourStoreName");
this.state.todos = [
{ text: "Your Data Goes Here", complete: false }
];
}
addTodo(text, complete) {
this.state.todos.push({ text, complete });
this.emitChange();
}
}
Or with TypeScript:
import Store from "rigby";
interface ToDo {
text: string;
complete: boolean;
}
interface YourStoreState {
todos: ToDo[];
}
class YourStore extends Store<YourStoreState> {
constructor() {
super("YourStoreName");
this.state.todos = [
{ text: "Your Data Goes Here", complete: false }
];
}
addTodo(text: string, complete: boolean) {
this.state.todos.push({ text, complete });
this.emitChange();
}
}
Dispatching Actions
import Rigby from "rigby";
Rigby.dispatch("addTodo", "Your New Todo", false);
Why
Less boilerplate when creating Stores and a more fluent API for doing so.
Plans
This is a thought experiment, and there are plans for versions that allow for using RxJS or move in the direction of things like Cycle and Yolk.