You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`fuse-react` is an abtraction on top of React Component which relieves the pain for those who find Redux overly complicated.
4
4
5
-
The concept is simple and revolves around a global Store object that is accessible by all components.
6
-
A component can "connect" to an individual key in the store and react to its changes.
7
-
8
-
9
-
The framework also offers a router which has some improvements comparing to `react-router`
10
-
11
-
```tsx
12
-
@connect("count")
13
-
classMyUserextendsFusion<any, any, MyStore> {
14
-
public render() {
15
-
return (
16
-
<div>{this.store.count}</div>
17
-
);
18
-
};
19
-
}
20
-
```
21
-
22
-
The decorator `@connect` registers subscription to the store, therefore once we update the object it will be forced to get updated.
23
-
24
-
```ts
25
-
dispatch("count", 1); // like this
26
-
dispatch({count : 1}); // or like this
27
-
```
28
-
29
-
## Create your store
30
-
31
-
```ts
32
-
import { createStore } from"fuse-react";
33
-
classMyStore {
34
-
count =0;
35
-
}
36
-
createStore(MyStore);
37
-
```
38
-
39
-
A class will be instantiated and registered globally
40
-
41
-
## Connecting
42
-
43
-
A component can be connected to individual keys in the store
44
-
```tsx
45
-
import { connect } from"fuse-react";
46
-
@connect("count", "user")
47
-
classMyUserextendsFusion<any, any, MyStore> {
48
-
public render() {
49
-
return (
50
-
<div>{this.store.count}</div>
51
-
);
52
-
};
53
-
}
54
-
```
55
5
56
-
The third (optional) generic typing will help with your typings on `this.store`, meanwhile the first and the second arguments remain conventional(IProps, IState)
57
-
58
-
### Connecting with deep compare
59
-
60
-
There are situations where you would like to avoid unnesserary updates. For that preffix your key with `@`
61
-
62
-
```ts
63
-
import { connect } from"fuse-react";
64
-
@connect("@user")
65
-
classMyUserextendsFusion<any, any, MyStore> {
66
-
public render() {
67
-
return (
68
-
<div>{this.store.user.name}</div>
69
-
);
70
-
};
71
-
}
72
-
```
6
+
The concept is simple and revolves around a global Store object that is accessible by all components.
73
7
74
-
Once the dispatcher recieves an event and goes through all subscriptions it will check if the new value is different from the one in the store.
8
+
`fuse-react` offers a solution to react routing which is more flexible and memory efficient than `react-router-dom`
75
9
76
-
### Init
77
10
78
-
```tsx
79
-
@connect("count", "user")
80
-
classMyUserextendsFusion<any, any, MyStore> {
81
-
private init(){}
82
-
public render() {
83
-
return (
84
-
<div>{this.store.count}</div>
85
-
);
86
-
};
87
-
}
88
-
```
89
11
90
-
It's important to understand the `init` of the component, it will be triggered on `componentWillMount` and `componentWillReceiveProps` as well as when a subscription key in the store has been changed.
12
+
## Router
91
13
92
-
Avoid dispatching events from `init` as it might cause an infinite loop.
14
+
FuseReact Router is very similar to `react-router`, in fact it mimics the API so the transition will be as smooth as possible.
93
15
94
-
### Dispatch
16
+

95
17
96
-
```tsx
97
-
import { dispatch } from"fuse-react";
98
-
dispatch("count", 1); // like this
99
-
dispatch({count : 1}); // or like this
100
-
```
18
+
Unlike `react-router``fuse-react router` subscribes to changes and renders only necessary components avoiding `render` from the top of the DOM tree.
101
19
102
20
103
-
## Router
21
+
Features:
104
22
105
-
FuseReact Router is very similar to `react-router`, in fact it mimics the API so the transition will be as smooth as possible.
23
+
* Memory efficient (render only required component)
24
+
* Extended Link support (a mini router)
25
+
* No wrapping the application
26
+
* Nothing else is required but `Switch` and `Route` (works with any React.Component framework)
In the case above `active` is `true` when navigated to `/user/foobar`, however the `navigate` function navigates to `/user/add`
112
+
184
113
### Navigation
185
114
186
115
Access navigation from anywhere in your code!
@@ -224,3 +153,102 @@ Additionally `setQuery` and `mergQuery` accept a second bool argument. Dispatch
224
153
mergQuery({foo : "bar"}, false)
225
154
// will result in `/user?hello=world&foo=bar`
226
155
```
156
+
157
+
A component can "connect" to an individual key in the store and react to its changes.
158
+
159
+
160
+
The framework also offers a router which has some improvements comparing to `react-router`
161
+
162
+
```tsx
163
+
@connect("count")
164
+
classMyUserextendsFusion<any, any, MyStore> {
165
+
public render() {
166
+
return (
167
+
<div>{this.store.count}</div>
168
+
);
169
+
};
170
+
}
171
+
```
172
+
173
+
The decorator `@connect` registers subscription to the store, therefore once we update the object it will be forced to get updated.
174
+
175
+
```ts
176
+
dispatch("count", 1); // like this
177
+
dispatch({count : 1}); // or like this
178
+
```
179
+
180
+
## Create your store
181
+
182
+
```ts
183
+
import { createStore } from"fuse-react";
184
+
classMyStore {
185
+
count =0;
186
+
}
187
+
createStore(MyStore);
188
+
```
189
+
190
+
A class will be instantiated and registered globally
191
+
192
+
## Connecting
193
+
194
+
A component can be connected to individual keys in the store
195
+
```tsx
196
+
import { connect } from"fuse-react";
197
+
@connect("count", "user")
198
+
classMyUserextendsFusion<any, any, MyStore> {
199
+
public render() {
200
+
return (
201
+
<div>{this.store.count}</div>
202
+
);
203
+
};
204
+
}
205
+
```
206
+
207
+
The third (optional) generic typing will help with your typings on `this.store`, meanwhile the first and the second arguments remain conventional(IProps, IState)
208
+
209
+
### Connecting with deep compare
210
+
211
+
There are situations where you would like to avoid unnesserary updates. For that preffix your key with `@`
212
+
213
+
```ts
214
+
import { connect } from"fuse-react";
215
+
@connect("@user")
216
+
classMyUserextendsFusion<any, any, MyStore> {
217
+
public render() {
218
+
return (
219
+
<div>{this.store.user.name}</div>
220
+
);
221
+
};
222
+
}
223
+
```
224
+
225
+
Once the dispatcher recieves an event and goes through all subscriptions it will check if the new value is different from the one in the store.
226
+
227
+
### Init
228
+
229
+
```tsx
230
+
@connect("count", "user")
231
+
classMyUserextendsFusion<any, any, MyStore> {
232
+
private init(){}
233
+
public render() {
234
+
return (
235
+
<div>{this.store.count}</div>
236
+
);
237
+
};
238
+
}
239
+
```
240
+
241
+
It's important to understand the `init` of the component, it will be triggered on `componentWillMount` and `componentWillReceiveProps` as well as when a subscription key in the store has been changed.
242
+
243
+
Avoid dispatching events from `init` as it might cause an infinite loop.
0 commit comments