@mantine/store 7.0.0-alpha.12 → 7.0.0-alpha.13
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/cjs/store.js +27 -23
- package/cjs/store.js.map +1 -1
- package/esm/store.js +27 -23
- package/esm/store.js.map +1 -1
- package/package.json +1 -1
package/cjs/store.js
CHANGED
|
@@ -5,31 +5,35 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var react = require('react');
|
|
6
6
|
|
|
7
7
|
function createStore(initialState) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
8
|
+
let state = initialState;
|
|
9
|
+
let initialized = false;
|
|
10
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
11
|
+
return {
|
|
12
|
+
getState() {
|
|
13
|
+
return state;
|
|
14
|
+
},
|
|
15
|
+
setState(value) {
|
|
16
|
+
state = value;
|
|
17
|
+
listeners.forEach((listener) => listener(state));
|
|
18
|
+
},
|
|
19
|
+
initialize(value) {
|
|
20
|
+
if (!initialized) {
|
|
21
|
+
state = value;
|
|
22
|
+
initialized = true;
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
subscribe(callback) {
|
|
26
|
+
listeners.add(callback);
|
|
27
|
+
return () => listeners.delete(callback);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
30
|
}
|
|
31
31
|
function useStore(store) {
|
|
32
|
-
|
|
32
|
+
return react.useSyncExternalStore(
|
|
33
|
+
store.subscribe,
|
|
34
|
+
() => store.getState(),
|
|
35
|
+
() => store.getState()
|
|
36
|
+
);
|
|
33
37
|
}
|
|
34
38
|
|
|
35
39
|
exports.createStore = createStore;
|
package/cjs/store.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.js","sources":["../src/store.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\n\nexport type MantineStoreSubscriber<Value> = (value: Value) => void;\n\nexport interface MantineStore<Value> {\n getState(): Value;\n setState(value: Value): void;\n initialize(value: Value): void;\n subscribe(callback: MantineStoreSubscriber<Value>): () => void;\n}\n\nexport type MantineStoreValue<Store extends MantineStore<any>> = ReturnType<Store['getState']>;\n\nexport function createStore<Value>(initialState: Value): MantineStore<Value> {\n let state = initialState;\n let initialized = false;\n const listeners = new Set<MantineStoreSubscriber<Value>>();\n\n return {\n getState() {\n return state;\n },\n\n setState(value) {\n state = value;\n listeners.forEach((listener) => listener(state));\n },\n\n initialize(value) {\n if (!initialized) {\n state = value;\n initialized = true;\n }\n },\n\n subscribe(callback) {\n listeners.add(callback);\n return () => listeners.delete(callback);\n },\n };\n}\n\nexport function useStore<Store extends MantineStore<any>>(store: Store) {\n return useSyncExternalStore<MantineStoreValue<Store>>(\n store.subscribe,\n () => store.getState(),\n () => store.getState()\n );\n}\n"],"names":["useSyncExternalStore"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"store.js","sources":["../src/store.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\n\nexport type MantineStoreSubscriber<Value> = (value: Value) => void;\n\nexport interface MantineStore<Value> {\n getState(): Value;\n setState(value: Value): void;\n initialize(value: Value): void;\n subscribe(callback: MantineStoreSubscriber<Value>): () => void;\n}\n\nexport type MantineStoreValue<Store extends MantineStore<any>> = ReturnType<Store['getState']>;\n\nexport function createStore<Value>(initialState: Value): MantineStore<Value> {\n let state = initialState;\n let initialized = false;\n const listeners = new Set<MantineStoreSubscriber<Value>>();\n\n return {\n getState() {\n return state;\n },\n\n setState(value) {\n state = value;\n listeners.forEach((listener) => listener(state));\n },\n\n initialize(value) {\n if (!initialized) {\n state = value;\n initialized = true;\n }\n },\n\n subscribe(callback) {\n listeners.add(callback);\n return () => listeners.delete(callback);\n },\n };\n}\n\nexport function useStore<Store extends MantineStore<any>>(store: Store) {\n return useSyncExternalStore<MantineStoreValue<Store>>(\n store.subscribe,\n () => store.getState(),\n () => store.getState()\n );\n}\n"],"names":["useSyncExternalStore"],"mappings":";;;;;;AACO,SAAS,WAAW,CAAC,YAAY,EAAE;AAC1C,EAAE,IAAI,KAAK,GAAG,YAAY,CAAC;AAC3B,EAAE,IAAI,WAAW,GAAG,KAAK,CAAC;AAC1B,EAAE,MAAM,SAAS,mBAAmB,IAAI,GAAG,EAAE,CAAC;AAC9C,EAAE,OAAO;AACT,IAAI,QAAQ,GAAG;AACf,MAAM,OAAO,KAAK,CAAC;AACnB,KAAK;AACL,IAAI,QAAQ,CAAC,KAAK,EAAE;AACpB,MAAM,KAAK,GAAG,KAAK,CAAC;AACpB,MAAM,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,KAAK,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;AACvD,KAAK;AACL,IAAI,UAAU,CAAC,KAAK,EAAE;AACtB,MAAM,IAAI,CAAC,WAAW,EAAE;AACxB,QAAQ,KAAK,GAAG,KAAK,CAAC;AACtB,QAAQ,WAAW,GAAG,IAAI,CAAC;AAC3B,OAAO;AACP,KAAK;AACL,IAAI,SAAS,CAAC,QAAQ,EAAE;AACxB,MAAM,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC9B,MAAM,OAAO,MAAM,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AAC9C,KAAK;AACL,GAAG,CAAC;AACJ,CAAC;AACM,SAAS,QAAQ,CAAC,KAAK,EAAE;AAChC,EAAE,OAAOA,0BAAoB;AAC7B,IAAI,KAAK,CAAC,SAAS;AACnB,IAAI,MAAM,KAAK,CAAC,QAAQ,EAAE;AAC1B,IAAI,MAAM,KAAK,CAAC,QAAQ,EAAE;AAC1B,GAAG,CAAC;AACJ;;;;;"}
|
package/esm/store.js
CHANGED
|
@@ -1,31 +1,35 @@
|
|
|
1
1
|
import { useSyncExternalStore } from 'react';
|
|
2
2
|
|
|
3
3
|
function createStore(initialState) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
4
|
+
let state = initialState;
|
|
5
|
+
let initialized = false;
|
|
6
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
7
|
+
return {
|
|
8
|
+
getState() {
|
|
9
|
+
return state;
|
|
10
|
+
},
|
|
11
|
+
setState(value) {
|
|
12
|
+
state = value;
|
|
13
|
+
listeners.forEach((listener) => listener(state));
|
|
14
|
+
},
|
|
15
|
+
initialize(value) {
|
|
16
|
+
if (!initialized) {
|
|
17
|
+
state = value;
|
|
18
|
+
initialized = true;
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
subscribe(callback) {
|
|
22
|
+
listeners.add(callback);
|
|
23
|
+
return () => listeners.delete(callback);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
26
|
}
|
|
27
27
|
function useStore(store) {
|
|
28
|
-
|
|
28
|
+
return useSyncExternalStore(
|
|
29
|
+
store.subscribe,
|
|
30
|
+
() => store.getState(),
|
|
31
|
+
() => store.getState()
|
|
32
|
+
);
|
|
29
33
|
}
|
|
30
34
|
|
|
31
35
|
export { createStore, useStore };
|
package/esm/store.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.js","sources":["../src/store.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\n\nexport type MantineStoreSubscriber<Value> = (value: Value) => void;\n\nexport interface MantineStore<Value> {\n getState(): Value;\n setState(value: Value): void;\n initialize(value: Value): void;\n subscribe(callback: MantineStoreSubscriber<Value>): () => void;\n}\n\nexport type MantineStoreValue<Store extends MantineStore<any>> = ReturnType<Store['getState']>;\n\nexport function createStore<Value>(initialState: Value): MantineStore<Value> {\n let state = initialState;\n let initialized = false;\n const listeners = new Set<MantineStoreSubscriber<Value>>();\n\n return {\n getState() {\n return state;\n },\n\n setState(value) {\n state = value;\n listeners.forEach((listener) => listener(state));\n },\n\n initialize(value) {\n if (!initialized) {\n state = value;\n initialized = true;\n }\n },\n\n subscribe(callback) {\n listeners.add(callback);\n return () => listeners.delete(callback);\n },\n };\n}\n\nexport function useStore<Store extends MantineStore<any>>(store: Store) {\n return useSyncExternalStore<MantineStoreValue<Store>>(\n store.subscribe,\n () => store.getState(),\n () => store.getState()\n );\n}\n"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"store.js","sources":["../src/store.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\n\nexport type MantineStoreSubscriber<Value> = (value: Value) => void;\n\nexport interface MantineStore<Value> {\n getState(): Value;\n setState(value: Value): void;\n initialize(value: Value): void;\n subscribe(callback: MantineStoreSubscriber<Value>): () => void;\n}\n\nexport type MantineStoreValue<Store extends MantineStore<any>> = ReturnType<Store['getState']>;\n\nexport function createStore<Value>(initialState: Value): MantineStore<Value> {\n let state = initialState;\n let initialized = false;\n const listeners = new Set<MantineStoreSubscriber<Value>>();\n\n return {\n getState() {\n return state;\n },\n\n setState(value) {\n state = value;\n listeners.forEach((listener) => listener(state));\n },\n\n initialize(value) {\n if (!initialized) {\n state = value;\n initialized = true;\n }\n },\n\n subscribe(callback) {\n listeners.add(callback);\n return () => listeners.delete(callback);\n },\n };\n}\n\nexport function useStore<Store extends MantineStore<any>>(store: Store) {\n return useSyncExternalStore<MantineStoreValue<Store>>(\n store.subscribe,\n () => store.getState(),\n () => store.getState()\n );\n}\n"],"names":[],"mappings":";;AACO,SAAS,WAAW,CAAC,YAAY,EAAE;AAC1C,EAAE,IAAI,KAAK,GAAG,YAAY,CAAC;AAC3B,EAAE,IAAI,WAAW,GAAG,KAAK,CAAC;AAC1B,EAAE,MAAM,SAAS,mBAAmB,IAAI,GAAG,EAAE,CAAC;AAC9C,EAAE,OAAO;AACT,IAAI,QAAQ,GAAG;AACf,MAAM,OAAO,KAAK,CAAC;AACnB,KAAK;AACL,IAAI,QAAQ,CAAC,KAAK,EAAE;AACpB,MAAM,KAAK,GAAG,KAAK,CAAC;AACpB,MAAM,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,KAAK,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;AACvD,KAAK;AACL,IAAI,UAAU,CAAC,KAAK,EAAE;AACtB,MAAM,IAAI,CAAC,WAAW,EAAE;AACxB,QAAQ,KAAK,GAAG,KAAK,CAAC;AACtB,QAAQ,WAAW,GAAG,IAAI,CAAC;AAC3B,OAAO;AACP,KAAK;AACL,IAAI,SAAS,CAAC,QAAQ,EAAE;AACxB,MAAM,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC9B,MAAM,OAAO,MAAM,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AAC9C,KAAK;AACL,GAAG,CAAC;AACJ,CAAC;AACM,SAAS,QAAQ,CAAC,KAAK,EAAE;AAChC,EAAE,OAAO,oBAAoB;AAC7B,IAAI,KAAK,CAAC,SAAS;AACnB,IAAI,MAAM,KAAK,CAAC,QAAQ,EAAE;AAC1B,IAAI,MAAM,KAAK,CAAC,QAAQ,EAAE;AAC1B,GAAG,CAAC;AACJ;;;;"}
|