ccstate 3.0.0 â 4.0.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 +12 -18
- package/core/index.cjs +8 -0
- package/core/index.d.cts +2 -1
- package/core/index.d.ts +2 -1
- package/core/index.js +8 -1
- package/debug/index.cjs +3 -2
- package/debug/index.js +3 -2
- package/index.cjs +11 -2
- package/index.d.cts +2 -1
- package/index.d.ts +2 -1
- package/index.js +11 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|

|
|
8
8
|

|
|
9
9
|
[](https://github.com/e7h4n/ccstate/actions/workflows/ci.yaml)
|
|
10
|
-
[](https://codspeed.io/e7h4n/ccstate)
|
|
11
10
|
[](https://opensource.org/licenses/MIT)
|
|
12
11
|
|
|
13
12
|
CCState is a semantic, strict, and flexible state management library suitable for medium to large single-page applications with complex state management needs.
|
|
@@ -19,7 +18,7 @@ The name of CCState comes from three basic data types: computed, command, and st
|
|
|
19
18
|
- ðŊ Simple & Intuitive: Crystal-clear API design with just 3 data types and 2 operations
|
|
20
19
|
- â
Rock-solid Reliability: Comprehensive test coverage reaching 100% branch coverage
|
|
21
20
|
- ðŠķ Ultra-lightweight: Zero dependencies, only 500 lines of core code
|
|
22
|
-
- ðĄ Framework Agnostic: Seamlessly works with [React](docs/react.md), [Vue](docs/vue.md), or any UI framework
|
|
21
|
+
- ðĄ Framework Agnostic: Seamlessly works with [React](docs/react.md), [Vue](docs/vue.md), [Solid.js](docs/solid.md), [Vanilla](docs/vanilla.md), or any UI framework
|
|
23
22
|
- ð Blazing Fast: Optimized performance from day one, 2x-7x faster than Jotai across scenarios
|
|
24
23
|
|
|
25
24
|
## Getting Started
|
|
@@ -85,27 +84,15 @@ export default function App() {
|
|
|
85
84
|
</div>
|
|
86
85
|
);
|
|
87
86
|
}
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
Use `createStore` and `StoreProvider` to provide a CCState store to React, all states and computations will only affect this isolated store.
|
|
91
87
|
|
|
92
|
-
```tsx
|
|
93
88
|
// main.jsx
|
|
94
|
-
import { createStore } from 'ccstate';
|
|
95
|
-
import { StoreProvider } from 'ccstate-react';
|
|
96
89
|
import { createRoot } from 'react-dom/client';
|
|
97
|
-
|
|
98
90
|
import App from './App';
|
|
99
91
|
|
|
100
92
|
const rootElement = document.getElementById('root');
|
|
101
93
|
const root = createRoot(rootElement);
|
|
102
94
|
|
|
103
|
-
|
|
104
|
-
root.render(
|
|
105
|
-
<StoreProvider value={store}>
|
|
106
|
-
<App />
|
|
107
|
-
</StoreProvider>,
|
|
108
|
-
);
|
|
95
|
+
root.render(<App />);
|
|
109
96
|
```
|
|
110
97
|
|
|
111
98
|
That's it! [Click here to see the full example](https://codesandbox.io/p/sandbox/cr3xg6).
|
|
@@ -288,6 +275,14 @@ That's it! Next, you can learn how to use CCState in React.
|
|
|
288
275
|
|
|
289
276
|
[Using in Vue](docs/vue.md)
|
|
290
277
|
|
|
278
|
+
## Using in Solid.js
|
|
279
|
+
|
|
280
|
+
[Using in Solid.js](docs/solid.md)
|
|
281
|
+
|
|
282
|
+
## Using in Vanilla
|
|
283
|
+
|
|
284
|
+
[Using in Vanilla](docs/vanilla.md)
|
|
285
|
+
|
|
291
286
|
### Testing & Debugging
|
|
292
287
|
|
|
293
288
|
Testing Value/Computed should be as simple as testing a Map.
|
|
@@ -821,10 +816,9 @@ So, I think the only way to implement `Computed`'s effect-less is to separate th
|
|
|
821
816
|
|
|
822
817
|
Here are some new ideas:
|
|
823
818
|
|
|
824
|
-
- Integration with svelte
|
|
825
|
-
- Enhance
|
|
819
|
+
- Integration with svelte
|
|
820
|
+
- Enhance debug ability
|
|
826
821
|
- Support viewing current subscription graph and related atom values
|
|
827
|
-
- Enable logging and breakpoints for specific atoms in devtools
|
|
828
822
|
- Performance improvements
|
|
829
823
|
- Mount atomState directly on atoms when there's only one store in the application to reduce WeakMap lookup overhead
|
|
830
824
|
- Support static declaration of upstream dependencies for Computed to improve performance by disabling runtime dependency analysis
|
package/core/index.cjs
CHANGED
|
@@ -1015,8 +1015,16 @@ function createStore() {
|
|
|
1015
1015
|
var listenerManager = new ListenerManager();
|
|
1016
1016
|
return new StoreImpl(atomManager, listenerManager);
|
|
1017
1017
|
}
|
|
1018
|
+
var defaultStore = undefined;
|
|
1019
|
+
function getDefaultStore() {
|
|
1020
|
+
if (!defaultStore) {
|
|
1021
|
+
defaultStore = createStore();
|
|
1022
|
+
}
|
|
1023
|
+
return defaultStore;
|
|
1024
|
+
}
|
|
1018
1025
|
|
|
1019
1026
|
exports.command = command;
|
|
1020
1027
|
exports.computed = computed;
|
|
1021
1028
|
exports.createStore = createStore;
|
|
1029
|
+
exports.getDefaultStore = getDefaultStore;
|
|
1022
1030
|
exports.state = state;
|
package/core/index.d.cts
CHANGED
|
@@ -48,5 +48,6 @@ type CallbackFunc<T> = Command<T, []>;
|
|
|
48
48
|
type Subscribe = (atoms$: ReadableAtom<unknown>[] | ReadableAtom<unknown>, callback: CallbackFunc<unknown>, options?: SubscribeOptions) => () => void;
|
|
49
49
|
|
|
50
50
|
declare function createStore(): Store;
|
|
51
|
+
declare function getDefaultStore(): Store;
|
|
51
52
|
|
|
52
|
-
export { type Command, type Computed, type Getter, type Read, type Setter, type State, type Store, type Subscribe, type Updater, type Write, command, computed, createStore, state };
|
|
53
|
+
export { type Command, type Computed, type Getter, type Read, type Setter, type State, type Store, type Subscribe, type Updater, type Write, command, computed, createStore, getDefaultStore, state };
|
package/core/index.d.ts
CHANGED
|
@@ -48,5 +48,6 @@ type CallbackFunc<T> = Command<T, []>;
|
|
|
48
48
|
type Subscribe = (atoms$: ReadableAtom<unknown>[] | ReadableAtom<unknown>, callback: CallbackFunc<unknown>, options?: SubscribeOptions) => () => void;
|
|
49
49
|
|
|
50
50
|
declare function createStore(): Store;
|
|
51
|
+
declare function getDefaultStore(): Store;
|
|
51
52
|
|
|
52
|
-
export { type Command, type Computed, type Getter, type Read, type Setter, type State, type Store, type Subscribe, type Updater, type Write, command, computed, createStore, state };
|
|
53
|
+
export { type Command, type Computed, type Getter, type Read, type Setter, type State, type Store, type Subscribe, type Updater, type Write, command, computed, createStore, getDefaultStore, state };
|
package/core/index.js
CHANGED
|
@@ -1013,5 +1013,12 @@ function createStore() {
|
|
|
1013
1013
|
var listenerManager = new ListenerManager();
|
|
1014
1014
|
return new StoreImpl(atomManager, listenerManager);
|
|
1015
1015
|
}
|
|
1016
|
+
var defaultStore = undefined;
|
|
1017
|
+
function getDefaultStore() {
|
|
1018
|
+
if (!defaultStore) {
|
|
1019
|
+
defaultStore = createStore();
|
|
1020
|
+
}
|
|
1021
|
+
return defaultStore;
|
|
1022
|
+
}
|
|
1016
1023
|
|
|
1017
|
-
export { command, computed, createStore, state };
|
|
1024
|
+
export { command, computed, createStore, getDefaultStore, state };
|
package/debug/index.cjs
CHANGED
|
@@ -1209,11 +1209,12 @@ var ConsoleInterceptor = /*#__PURE__*/_createClass(function ConsoleInterceptor(w
|
|
|
1209
1209
|
function createDebugStore() {
|
|
1210
1210
|
var watches = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
1211
1211
|
var defaultActions = arguments.length > 1 ? arguments[1] : undefined;
|
|
1212
|
+
var parsedDefaultActions = defaultActions ? new Set(defaultActions) : undefined;
|
|
1212
1213
|
var parsedWatches = watches.map(function (watch) {
|
|
1213
1214
|
if (typeof watch === 'string' || watch instanceof RegExp) {
|
|
1214
1215
|
return {
|
|
1215
1216
|
target: watch,
|
|
1216
|
-
actions:
|
|
1217
|
+
actions: parsedDefaultActions
|
|
1217
1218
|
};
|
|
1218
1219
|
}
|
|
1219
1220
|
if ('target' in watch) {
|
|
@@ -1221,7 +1222,7 @@ function createDebugStore() {
|
|
|
1221
1222
|
}
|
|
1222
1223
|
return {
|
|
1223
1224
|
target: watch,
|
|
1224
|
-
actions:
|
|
1225
|
+
actions: parsedDefaultActions
|
|
1225
1226
|
};
|
|
1226
1227
|
});
|
|
1227
1228
|
var interceptor = new ConsoleInterceptor(parsedWatches);
|
package/debug/index.js
CHANGED
|
@@ -1207,11 +1207,12 @@ var ConsoleInterceptor = /*#__PURE__*/_createClass(function ConsoleInterceptor(w
|
|
|
1207
1207
|
function createDebugStore() {
|
|
1208
1208
|
var watches = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
1209
1209
|
var defaultActions = arguments.length > 1 ? arguments[1] : undefined;
|
|
1210
|
+
var parsedDefaultActions = defaultActions ? new Set(defaultActions) : undefined;
|
|
1210
1211
|
var parsedWatches = watches.map(function (watch) {
|
|
1211
1212
|
if (typeof watch === 'string' || watch instanceof RegExp) {
|
|
1212
1213
|
return {
|
|
1213
1214
|
target: watch,
|
|
1214
|
-
actions:
|
|
1215
|
+
actions: parsedDefaultActions
|
|
1215
1216
|
};
|
|
1216
1217
|
}
|
|
1217
1218
|
if ('target' in watch) {
|
|
@@ -1219,7 +1220,7 @@ function createDebugStore() {
|
|
|
1219
1220
|
}
|
|
1220
1221
|
return {
|
|
1221
1222
|
target: watch,
|
|
1222
|
-
actions:
|
|
1223
|
+
actions: parsedDefaultActions
|
|
1223
1224
|
};
|
|
1224
1225
|
});
|
|
1225
1226
|
var interceptor = new ConsoleInterceptor(parsedWatches);
|
package/index.cjs
CHANGED
|
@@ -1076,6 +1076,13 @@ function createStore() {
|
|
|
1076
1076
|
var listenerManager = new ListenerManager();
|
|
1077
1077
|
return new StoreImpl(atomManager, listenerManager);
|
|
1078
1078
|
}
|
|
1079
|
+
var defaultStore = undefined;
|
|
1080
|
+
function getDefaultStore() {
|
|
1081
|
+
if (!defaultStore) {
|
|
1082
|
+
defaultStore = createStore();
|
|
1083
|
+
}
|
|
1084
|
+
return defaultStore;
|
|
1085
|
+
}
|
|
1079
1086
|
|
|
1080
1087
|
var DebugStoreImpl = /*#__PURE__*/function (_StoreImpl) {
|
|
1081
1088
|
function DebugStoreImpl() {
|
|
@@ -1253,11 +1260,12 @@ var ConsoleInterceptor = /*#__PURE__*/_createClass(function ConsoleInterceptor(w
|
|
|
1253
1260
|
function createDebugStore() {
|
|
1254
1261
|
var watches = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
1255
1262
|
var defaultActions = arguments.length > 1 ? arguments[1] : undefined;
|
|
1263
|
+
var parsedDefaultActions = defaultActions ? new Set(defaultActions) : undefined;
|
|
1256
1264
|
var parsedWatches = watches.map(function (watch) {
|
|
1257
1265
|
if (typeof watch === 'string' || watch instanceof RegExp) {
|
|
1258
1266
|
return {
|
|
1259
1267
|
target: watch,
|
|
1260
|
-
actions:
|
|
1268
|
+
actions: parsedDefaultActions
|
|
1261
1269
|
};
|
|
1262
1270
|
}
|
|
1263
1271
|
if ('target' in watch) {
|
|
@@ -1265,7 +1273,7 @@ function createDebugStore() {
|
|
|
1265
1273
|
}
|
|
1266
1274
|
return {
|
|
1267
1275
|
target: watch,
|
|
1268
|
-
actions:
|
|
1276
|
+
actions: parsedDefaultActions
|
|
1269
1277
|
};
|
|
1270
1278
|
});
|
|
1271
1279
|
var interceptor = new ConsoleInterceptor(parsedWatches);
|
|
@@ -1276,4 +1284,5 @@ exports.command = command;
|
|
|
1276
1284
|
exports.computed = computed;
|
|
1277
1285
|
exports.createDebugStore = createDebugStore;
|
|
1278
1286
|
exports.createStore = createStore;
|
|
1287
|
+
exports.getDefaultStore = getDefaultStore;
|
|
1279
1288
|
exports.state = state;
|
package/index.d.cts
CHANGED
|
@@ -49,6 +49,7 @@ type Subscribe = (atoms$: ReadableAtom<unknown>[] | ReadableAtom<unknown>, callb
|
|
|
49
49
|
type StoreEventType = 'set' | 'get' | 'sub' | 'unsub' | 'mount' | 'unmount' | 'notify' | 'computed';
|
|
50
50
|
|
|
51
51
|
declare function createStore(): Store;
|
|
52
|
+
declare function getDefaultStore(): Store;
|
|
52
53
|
|
|
53
54
|
type NestedAtom = (State<unknown> | Computed<unknown> | Command<unknown, unknown[]> | NestedAtom)[];
|
|
54
55
|
interface DebugStore extends Store {
|
|
@@ -64,4 +65,4 @@ interface AtomWatch {
|
|
|
64
65
|
}
|
|
65
66
|
declare function createDebugStore(watches?: (AtomWatch | string | RegExp | State<unknown> | Computed<unknown> | Command<unknown, unknown[]>)[], defaultActions?: StoreEventType[]): DebugStore;
|
|
66
67
|
|
|
67
|
-
export { type Command, type Computed, type DebugStore, type Getter, type Read, type Setter, type State, type Store, type Subscribe, type Updater, type Write, command, computed, createDebugStore, createStore, state };
|
|
68
|
+
export { type Command, type Computed, type DebugStore, type Getter, type Read, type Setter, type State, type Store, type Subscribe, type Updater, type Write, command, computed, createDebugStore, createStore, getDefaultStore, state };
|
package/index.d.ts
CHANGED
|
@@ -49,6 +49,7 @@ type Subscribe = (atoms$: ReadableAtom<unknown>[] | ReadableAtom<unknown>, callb
|
|
|
49
49
|
type StoreEventType = 'set' | 'get' | 'sub' | 'unsub' | 'mount' | 'unmount' | 'notify' | 'computed';
|
|
50
50
|
|
|
51
51
|
declare function createStore(): Store;
|
|
52
|
+
declare function getDefaultStore(): Store;
|
|
52
53
|
|
|
53
54
|
type NestedAtom = (State<unknown> | Computed<unknown> | Command<unknown, unknown[]> | NestedAtom)[];
|
|
54
55
|
interface DebugStore extends Store {
|
|
@@ -64,4 +65,4 @@ interface AtomWatch {
|
|
|
64
65
|
}
|
|
65
66
|
declare function createDebugStore(watches?: (AtomWatch | string | RegExp | State<unknown> | Computed<unknown> | Command<unknown, unknown[]>)[], defaultActions?: StoreEventType[]): DebugStore;
|
|
66
67
|
|
|
67
|
-
export { type Command, type Computed, type DebugStore, type Getter, type Read, type Setter, type State, type Store, type Subscribe, type Updater, type Write, command, computed, createDebugStore, createStore, state };
|
|
68
|
+
export { type Command, type Computed, type DebugStore, type Getter, type Read, type Setter, type State, type Store, type Subscribe, type Updater, type Write, command, computed, createDebugStore, createStore, getDefaultStore, state };
|
package/index.js
CHANGED
|
@@ -1074,6 +1074,13 @@ function createStore() {
|
|
|
1074
1074
|
var listenerManager = new ListenerManager();
|
|
1075
1075
|
return new StoreImpl(atomManager, listenerManager);
|
|
1076
1076
|
}
|
|
1077
|
+
var defaultStore = undefined;
|
|
1078
|
+
function getDefaultStore() {
|
|
1079
|
+
if (!defaultStore) {
|
|
1080
|
+
defaultStore = createStore();
|
|
1081
|
+
}
|
|
1082
|
+
return defaultStore;
|
|
1083
|
+
}
|
|
1077
1084
|
|
|
1078
1085
|
var DebugStoreImpl = /*#__PURE__*/function (_StoreImpl) {
|
|
1079
1086
|
function DebugStoreImpl() {
|
|
@@ -1251,11 +1258,12 @@ var ConsoleInterceptor = /*#__PURE__*/_createClass(function ConsoleInterceptor(w
|
|
|
1251
1258
|
function createDebugStore() {
|
|
1252
1259
|
var watches = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
1253
1260
|
var defaultActions = arguments.length > 1 ? arguments[1] : undefined;
|
|
1261
|
+
var parsedDefaultActions = defaultActions ? new Set(defaultActions) : undefined;
|
|
1254
1262
|
var parsedWatches = watches.map(function (watch) {
|
|
1255
1263
|
if (typeof watch === 'string' || watch instanceof RegExp) {
|
|
1256
1264
|
return {
|
|
1257
1265
|
target: watch,
|
|
1258
|
-
actions:
|
|
1266
|
+
actions: parsedDefaultActions
|
|
1259
1267
|
};
|
|
1260
1268
|
}
|
|
1261
1269
|
if ('target' in watch) {
|
|
@@ -1263,11 +1271,11 @@ function createDebugStore() {
|
|
|
1263
1271
|
}
|
|
1264
1272
|
return {
|
|
1265
1273
|
target: watch,
|
|
1266
|
-
actions:
|
|
1274
|
+
actions: parsedDefaultActions
|
|
1267
1275
|
};
|
|
1268
1276
|
});
|
|
1269
1277
|
var interceptor = new ConsoleInterceptor(parsedWatches);
|
|
1270
1278
|
return createDebugStoreInternal(interceptor);
|
|
1271
1279
|
}
|
|
1272
1280
|
|
|
1273
|
-
export { command, computed, createDebugStore, createStore, state };
|
|
1281
|
+
export { command, computed, createDebugStore, createStore, getDefaultStore, state };
|