immu-js 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,13 +2,33 @@
|
|
|
2
2
|
|
|
3
3
|
A tiny (~2 KB), zero-dependency, framework-independent, store based, reactive state library for JavaScript applications. It's very similar to redux in terms of functionality, but it's much simpler to work with immutable objects.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
### Why immu-js over redux or zustand or signals?
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- **Easier and Simpler**: immu-js is much easier and simpler to work with than redux. No actions to dispatch. Automatic tracking (no need to pass dependencies to effects and memos).
|
|
8
|
+
- **Store-based**: Unlike signals which are function-based, immu-js is store-based. It lets you group multiple states into one store and import it into wherever you need.
|
|
9
|
+
- **More options**: immu-js has more options for effects and memos than signals. like you can control when you want to run Effect function by passing dependencies to it which are optional. If no deps passed, then it'll call the effect function when any stores that are used change. if you pass the dependencies, effects are run only if they change.
|
|
10
|
+
- **Framework-independent**: immu-js is framework-independent, which means you can use it with any framework or library but you will need adapters for frameworks if you want to use it with them.
|
|
11
|
+
- **Zero-dependency**: immu-js has zero-dependency, which means you don't need to install any other packages to use it.
|
|
12
|
+
- **TypeScript support**: immu-js has full TypeScript support and type inference.
|
|
13
|
+
- **100% test coverage**: immu-js has 100% test coverage, which means you can trust it to work as expected.
|
|
14
|
+
- **Small bundle size**: immu-js is very small around 2kb.
|
|
8
15
|
|
|
9
|
-
use `create` function to create a store from a class, use `run` to run effects (similar to effect in signals), use `memo` to create a computed getter that lets you pass arguments to it and caches the computed result based on stores used in the function and also arguments passed to that function. Use `computed` to create a signals like computed object with value property that has auto computed property. You can also save the store as a version so you can roll back along with `reset` function to reset your stores. That's it.
|
|
10
16
|
|
|
11
|
-
|
|
17
|
+
### How to use?
|
|
18
|
+
**`create`** function to create a store from a class.
|
|
19
|
+
|
|
20
|
+
**`run`** to run effects (similar to effect in signals).
|
|
21
|
+
|
|
22
|
+
**`memo`** to create a computed getter that lets you pass arguments to it and caches the computed result based on stores used in the function and also arguments passed to that function.
|
|
23
|
+
|
|
24
|
+
**`computed`** to create a signals like computed object with value property that has auto computed property. You can also save the store as a version so you can roll back to previous versions.
|
|
25
|
+
|
|
26
|
+
**`reset`** function to reset your stores. That's it.
|
|
27
|
+
|
|
28
|
+
### How does it work?
|
|
29
|
+
It creates getters and setters for the store properties to track when they are read or written.
|
|
30
|
+
|
|
31
|
+
You have to assign new values to the properties in the class to detect the change. Library creates a getter and setter for each and every property in the class after creating an instance to track when they are read or written, so by setting the value through function or from outside, library will know that this value has changed. It treats your store values as immutable. so you will need to reacreate the references for the values at the root level when anything inside the object or array changes. values can be of any type.
|
|
12
32
|
|
|
13
33
|
```typescript
|
|
14
34
|
import { create, memo, computed, run } from "immu-js";
|