Skip to content

Commit a3b48ba

Browse files
committed
first commit
1 parent 077282b commit a3b48ba

24 files changed

+70185
-2
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,5 @@ typings/
5757
# dotenv environment variables file
5858
.env
5959

60+
# reify cache for allowing import export in node
61+
.reify-cache

README.md

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,65 @@
1-
# react-easy-state
2-
A small observer library that replaces React.setState with direct mutations. (WIP)
1+
# React Easy State
2+
3+
Easy State aims to make React's state management simpler without adding new syntax. To achieve this it makes the following modifications.
4+
5+
- It replaces React's `setState()` with plain native JavaScript.
6+
- It bypasses the asynchronity and performance issues of `setState`.
7+
- It auto binds your component's methods.
8+
9+
## Installation
10+
11+
`npm i react-easy-state --save`
12+
13+
## Usage
14+
15+
```js
16+
import React, { Component } from 'react'
17+
import easyState from 'react-easy-state'
18+
19+
@easyState
20+
export default class App extends Component {
21+
render() {
22+
const { name } = this.state
23+
24+
return (
25+
<div>
26+
<div>Name: <input onChange={this.updateName}/></div>
27+
<p>Hello {name}!</p>
28+
</div>
29+
)
30+
}
31+
32+
updateName (ev) {
33+
this.state.name = ev.target.value
34+
}
35+
}
36+
```
37+
38+
You can find more examples with live demos [here](/examples).
39+
40+
### About decorators
41+
42+
`@easyState` is a decorator, which is not yet part of the JS language. You can learn how to enable decorators with babel [here](https://github.com/loganfsmyth/babel-plugin-transform-decorators-legacy) or you can use the older `export default easyState(Comp)` syntax.
43+
44+
## Platform support
45+
46+
- Node: 6 and above
47+
- Chrome: 49 and above
48+
- Firefox: 38 and above
49+
- Safari: 10 and above
50+
- Edge: 12 and above
51+
- Opera: 36 and above
52+
- React native is not yet supported
53+
- IE is not supported
54+
55+
## How does it work?
56+
57+
Under the hood it uses the [@nx-js/observer-util](https://github.com/nx-js/observer-util) library, which relies on ES6 proxies to observe state changes. Thanks to the Proxies it doesn't have edge cases or limitations. You can write any JS code without worrying about the render function. [This blog post](https://blog.risingstack.com/writing-a-javascript-framework-data-binding-es6-proxy/) gives a little sneak peek under the hood of the `observer-util`.
58+
59+
## Contributing
60+
61+
Contributions are always welcome. Just send a PR against the master branch or open a new issue. Please make sure that the tests and the linter pass and the coverage remains at 100%. Thx!
62+
63+
## The NX Framework
64+
65+
This library is the side effect of a front-end framework I have been working on in the past year. Please take a look at the [NX Framework](https://nx-framework.com/) if you have some time. Have a nice day!

0 commit comments

Comments
 (0)