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
Copy file name to clipboardExpand all lines: README.md
+26-8Lines changed: 26 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -78,18 +78,12 @@ function Page() {
78
78
79
79
This adjusted code snippet provides a simple and easy-to-understand usage example of the `emittor` package. It demonstrates using the `useEmittor` hook to manage state, similar to how `useState` is used in React.
80
80
81
+
</br>
82
+
81
83
> **Warning** </br>
82
84
> Always create an emittor in a separate file</br>
83
85
> Because in development mode, the whole file will be rendered again. That can cause unexpected bugs.
84
86
85
-
.
86
-
87
-
> **Note** </br>
88
-
> create emittor anywhere in your project like [`createContext`](https://react.dev/reference/react/createContext) in React. </br>
89
-
> and import `Emittor` where use or link (in components and other places)
90
-
91
-
</br>
92
-
93
87
## Emittor In Multiple Components
94
88
95
89
The emittor package enables automatic state synchronization across React components. By simply integrating emittor, any component subscribing to state changes will update whenever the state changes anywhere in the application. This eliminates the need for manual state passing or provider wrapping, streamlining development and enhancing component responsiveness.
@@ -242,6 +236,30 @@ export default function Page() {
|`constructor(initialState: T, options: { match?: boolean })`| Initializes an instance of `Emittor` with an initial state and optional matching behavior. If `options.match` is true, `setMatchState` and `emit` are bound to handle state updates; otherwise, `setOnlyState` and `emit` are used. |
252
+
|`setState()`, `emit()`| Sets the state and Executes all subscribed callbacks (also use `state`) |
253
+
|`getState()`| Returns the current state (also use `state`). |
254
+
|`state`| Is current state (with `get` & `set`) you can modify directly. |
255
+
|`exec()`, `refresh()`| Executes all subscribed callbacks with the current state. |
256
+
|`run(state: T)`| Executes all callbacks with the provided `state` (this will not changed current state). |
257
+
|`connect(callback: Callback<T>)`| Adds the `callback` to the list of callbacks to be executed on state changes. |
258
+
|`disconnect(callback: Callback<T>)`| Removes the specified `callback` from the list of callbacks. |
259
+
|*`setOnlyState(state: T)`| Updates the state without checking and executes all subscribed callbacks. |
260
+
|*`setMatchState(state: T)`| Updates the state only if the new `state` differs from the current state and then executes `setOnlyState(state)`. |
0 commit comments