Skip to content

Commit c99c998

Browse files
committed
docs(readme): fix a few issues
1 parent ed5b1ae commit c99c998

File tree

5 files changed

+148
-54
lines changed

5 files changed

+148
-54
lines changed

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Simple React state management. Made with :heart: and ES6 Proxies.
66

77
<a href="#platform-support"><img src="images/browser_support.png" alt="Browser support" width="450px" /></a>
88

9-
**Breaking change in [v5](https://github.com/solkimicreb/react-easy-state/releases/tag/v5.0.0)**: the auto bind feature got removed. See the alternatives for your components at the [official React docs](https://reactjs.org/docs/handling-events.html) and for you stores at [the FAQ docs section](#my-stores-are-broken).
9+
**Breaking change in [v5](https://github.com/solkimicreb/react-easy-state/releases/tag/v5.0.0)**: the auto bind feature got removed. See the alternatives for your components at the [official React docs](https://reactjs.org/docs/handling-events.html) and for you stores at [the FAQ docs section](#my-store-methods-are-broken).
1010

1111
<details>
1212
<summary><strong>Table of Contents</strong></summary>
@@ -39,13 +39,11 @@ Simple React state management. Made with :heart: and ES6 Proxies.
3939

4040
## Introduction
4141

42-
Easy State has two rules:
42+
Easy State has two rules.
4343

4444
1. Always wrap you components with `view`.
4545
2. Always wrap you state store objects with `store`.
4646

47-
This is enough for it to automatically update your views when needed - no matter how exotically you mutate your state stores. With this freedom you can invent and use your personal favorite state management patterns.
48-
4947
```js
5048
import React from 'react'
5149
import { store, view } from 'react-easy-state'
@@ -56,6 +54,8 @@ setInterval(() => clock.time = new Date(), 1000)
5654
export default view(() => <div>{clock.time}</div>)
5755
```
5856

57+
This is enough for it to automatically update your views when needed - no matter how exotically you mutate your state stores. With this freedom you can invent and use your personal favorite state management patterns.
58+
5959
## Installation
6060

6161
`npm install react-easy-state`
@@ -240,7 +240,7 @@ This works as expected, even when you pass store methods as callbacks.
240240

241241
### My views are not rendering
242242

243-
You should wrap your state stores in `store` as early as possible to make them reactive.
243+
You should wrap your state stores with `store` as early as possible to make them reactive.
244244

245245
```js
246246
const person = { name: 'Bob' }
@@ -249,7 +249,9 @@ person.name = 'Ann'
249249
export default store(person)
250250
```
251251

252-
The above example wouldn't cause any re-renders on the `person.name = 'Ann'` mutation, because it is targeted at the raw object. Mutating the raw - none `store` wrapped object - won't schedule renders. Do this instead of the above code.
252+
The above example wouldn't trigger re-renders on the `person.name = 'Ann'` mutation, because it is targeted at the raw object. Mutating the raw - none `store` wrapped object - won't schedule renders.
253+
254+
Do this instead of the above code.
253255

254256
```js
255257
const person = store({ name: 'Bob' })

examples/clock/dist/bundle.js

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14165,6 +14165,7 @@ function releaseReactionKeyConnection(reactionsForKey) {
1416514165
}
1416614166

1416714167
var runningReaction;
14168+
var isDebugging = false;
1416814169

1416914170
function runAsReaction(reaction, fn, context, args) {
1417014171
// do not build reactive relations, if the reaction is unobserved
@@ -14190,9 +14191,7 @@ function runAsReaction(reaction, fn, context, args) {
1419014191
// register the currently running reaction to be queued again on obj.key mutations
1419114192
function registerRunningReactionForOperation(operation) {
1419214193
if (runningReaction) {
14193-
if (runningReaction.debugger) {
14194-
runningReaction.debugger(operation);
14195-
}
14194+
debugOperation(runningReaction, operation);
1419614195
registerReactionForOperation(runningReaction, operation);
1419714196
}
1419814197
}
@@ -14203,9 +14202,7 @@ function queueReactionsForOperation(operation) {
1420314202
}
1420414203

1420514204
function queueReaction(reaction) {
14206-
if (reaction.debugger) {
14207-
reaction.debugger(this);
14208-
}
14205+
debugOperation(reaction, this);
1420914206
// queue the reaction for later execution or run it immediately
1421014207
if (typeof reaction.scheduler === 'function') {
1421114208
reaction.scheduler(reaction);
@@ -14216,6 +14213,17 @@ function queueReaction(reaction) {
1421614213
}
1421714214
}
1421814215

14216+
function debugOperation(reaction, operation) {
14217+
if (reaction.debugger && !isDebugging) {
14218+
try {
14219+
isDebugging = true;
14220+
reaction.debugger(operation);
14221+
} finally {
14222+
isDebugging = false;
14223+
}
14224+
}
14225+
}
14226+
1421914227
function hasRunningReaction() {
1422014228
return runningReaction !== undefined;
1422114229
}
@@ -14454,7 +14462,14 @@ function set(target, key, value, receiver) {
1445414462
if (!hadKey) {
1445514463
queueReactionsForOperation({ target: target, key: key, value: value, receiver: receiver, type: 'add' });
1445614464
} else if (value !== oldValue) {
14457-
queueReactionsForOperation({ target: target, key: key, value: value, oldValue: oldValue, receiver: receiver, type: 'set' });
14465+
queueReactionsForOperation({
14466+
target: target,
14467+
key: key,
14468+
value: value,
14469+
oldValue: oldValue,
14470+
receiver: receiver,
14471+
type: 'set'
14472+
});
1445814473
}
1445914474
return result;
1446014475
}
@@ -27022,14 +27037,12 @@ module.exports = ReactDOMInvalidARIAHook;
2702227037

2702327038

2702427039

27025-
function view(Comp) {
27040+
function view(Comp, { devtool: rawDevtool } = {}) {
2702627041
var _class, _temp;
2702727042

2702827043
const isStatelessComp = !(Comp.prototype && Comp.prototype.isReactComponent);
2702927044
const BaseComp = isStatelessComp ? __WEBPACK_IMPORTED_MODULE_0_react__["Component"] : Comp;
2703027045

27031-
const rawDevtool = typeof __REACT_EASY_STATE_DEVTOOL__ === 'function' && __REACT_EASY_STATE_DEVTOOL__;
27032-
2703327046
const devtool = rawDevtool ? operation => rawDevtool(Object.assign({ Component: Comp }, operation)) : undefined;
2703427047

2703527048
// return a HOC which overwrites render, shouldComponentUpdate and componentWillUnmount
@@ -27049,7 +27062,6 @@ function view(Comp) {
2704927062
}
2705027063

2705127064
render() {
27052-
devtool && devtool({ type: 'render' });
2705327065
return isStatelessComp ? Comp(this.props, this.context) : super.render();
2705427066
}
2705527067

@@ -27059,18 +27071,29 @@ function view(Comp) {
2705927071

2706027072
// respect the case when user prohibits updates
2706127073
if (super.shouldComponentUpdate && !super.shouldComponentUpdate(nextProps, nextState)) {
27074+
devtool && devtool({ type: 'render', renderType: 'blocked' });
2706227075
return false;
2706327076
}
2706427077

2706527078
// return true if it is a reactive render or state changes
2706627079
if (state !== nextState) {
27080+
devtool && devtool({ type: 'render', renderType: 'reactive' });
2706727081
return true;
2706827082
}
2706927083

2707027084
// the component should update if any of its props shallowly changed value
2707127085
const keys = Object.keys(props);
2707227086
const nextKeys = Object.keys(nextProps);
27073-
return nextKeys.length !== keys.length || nextKeys.some(key => props[key] !== nextProps[key]);
27087+
if (nextKeys.length !== keys.length || nextKeys.some(key => props[key] !== nextProps[key])) {
27088+
devtool && devtool({
27089+
type: 'render',
27090+
renderType: 'normal',
27091+
props: nextProps,
27092+
oldProps: props
27093+
});
27094+
return true;
27095+
}
27096+
return false;
2707427097
}
2707527098

2707627099
componentWillUnmount() {

examples/contacts/dist/bundle.js

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9811,6 +9811,7 @@ function releaseReactionKeyConnection(reactionsForKey) {
98119811
}
98129812

98139813
var runningReaction;
9814+
var isDebugging = false;
98149815

98159816
function runAsReaction(reaction, fn, context, args) {
98169817
// do not build reactive relations, if the reaction is unobserved
@@ -9836,9 +9837,7 @@ function runAsReaction(reaction, fn, context, args) {
98369837
// register the currently running reaction to be queued again on obj.key mutations
98379838
function registerRunningReactionForOperation(operation) {
98389839
if (runningReaction) {
9839-
if (runningReaction.debugger) {
9840-
runningReaction.debugger(operation);
9841-
}
9840+
debugOperation(runningReaction, operation);
98429841
registerReactionForOperation(runningReaction, operation);
98439842
}
98449843
}
@@ -9849,9 +9848,7 @@ function queueReactionsForOperation(operation) {
98499848
}
98509849

98519850
function queueReaction(reaction) {
9852-
if (reaction.debugger) {
9853-
reaction.debugger(this);
9854-
}
9851+
debugOperation(reaction, this);
98559852
// queue the reaction for later execution or run it immediately
98569853
if (typeof reaction.scheduler === 'function') {
98579854
reaction.scheduler(reaction);
@@ -9862,6 +9859,17 @@ function queueReaction(reaction) {
98629859
}
98639860
}
98649861

9862+
function debugOperation(reaction, operation) {
9863+
if (reaction.debugger && !isDebugging) {
9864+
try {
9865+
isDebugging = true;
9866+
reaction.debugger(operation);
9867+
} finally {
9868+
isDebugging = false;
9869+
}
9870+
}
9871+
}
9872+
98659873
function hasRunningReaction() {
98669874
return runningReaction !== undefined;
98679875
}
@@ -10100,7 +10108,14 @@ function set(target, key, value, receiver) {
1010010108
if (!hadKey) {
1010110109
queueReactionsForOperation({ target: target, key: key, value: value, receiver: receiver, type: 'add' });
1010210110
} else if (value !== oldValue) {
10103-
queueReactionsForOperation({ target: target, key: key, value: value, oldValue: oldValue, receiver: receiver, type: 'set' });
10111+
queueReactionsForOperation({
10112+
target: target,
10113+
key: key,
10114+
value: value,
10115+
oldValue: oldValue,
10116+
receiver: receiver,
10117+
type: 'set'
10118+
});
1010410119
}
1010510120
return result;
1010610121
}
@@ -22668,14 +22683,12 @@ module.exports = ReactDOMInvalidARIAHook;
2266822683

2266922684

2267022685

22671-
function view(Comp) {
22686+
function view(Comp, { devtool: rawDevtool } = {}) {
2267222687
var _class, _temp;
2267322688

2267422689
const isStatelessComp = !(Comp.prototype && Comp.prototype.isReactComponent);
2267522690
const BaseComp = isStatelessComp ? __WEBPACK_IMPORTED_MODULE_0_react__["Component"] : Comp;
2267622691

22677-
const rawDevtool = typeof __REACT_EASY_STATE_DEVTOOL__ === 'function' && __REACT_EASY_STATE_DEVTOOL__;
22678-
2267922692
const devtool = rawDevtool ? operation => rawDevtool(Object.assign({ Component: Comp }, operation)) : undefined;
2268022693

2268122694
// return a HOC which overwrites render, shouldComponentUpdate and componentWillUnmount
@@ -22695,7 +22708,6 @@ function view(Comp) {
2269522708
}
2269622709

2269722710
render() {
22698-
devtool && devtool({ type: 'render' });
2269922711
return isStatelessComp ? Comp(this.props, this.context) : super.render();
2270022712
}
2270122713

@@ -22705,18 +22717,29 @@ function view(Comp) {
2270522717

2270622718
// respect the case when user prohibits updates
2270722719
if (super.shouldComponentUpdate && !super.shouldComponentUpdate(nextProps, nextState)) {
22720+
devtool && devtool({ type: 'render', renderType: 'blocked' });
2270822721
return false;
2270922722
}
2271022723

2271122724
// return true if it is a reactive render or state changes
2271222725
if (state !== nextState) {
22726+
devtool && devtool({ type: 'render', renderType: 'reactive' });
2271322727
return true;
2271422728
}
2271522729

2271622730
// the component should update if any of its props shallowly changed value
2271722731
const keys = Object.keys(props);
2271822732
const nextKeys = Object.keys(nextProps);
22719-
return nextKeys.length !== keys.length || nextKeys.some(key => props[key] !== nextProps[key]);
22733+
if (nextKeys.length !== keys.length || nextKeys.some(key => props[key] !== nextProps[key])) {
22734+
devtool && devtool({
22735+
type: 'render',
22736+
renderType: 'normal',
22737+
props: nextProps,
22738+
oldProps: props
22739+
});
22740+
return true;
22741+
}
22742+
return false;
2272022743
}
2272122744

2272222745
componentWillUnmount() {

0 commit comments

Comments
 (0)