@tanstack/react-store 0.0.1 → 0.1.1
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/package.json +28 -12
- package/src/__tests__/index.test.tsx +79 -0
- package/src/index.tsx +1 -2
- package/build/cjs/index.js +0 -49
- package/build/cjs/index.js.map +0 -1
- package/build/esm/index.js +0 -38
- package/build/esm/index.js.map +0 -1
- package/build/stats-html.html +0 -4044
- package/build/stats-react.json +0 -90
- package/build/types/index.d.ts +0 -18
- package/build/umd/index.development.js +0 -113
- package/build/umd/index.development.js.map +0 -1
- package/build/umd/index.production.js +0 -22
- package/build/umd/index.production.js.map +0 -1
package/build/stats-react.json
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 2,
|
|
3
|
-
"tree": {
|
|
4
|
-
"name": "root",
|
|
5
|
-
"children": [
|
|
6
|
-
{
|
|
7
|
-
"name": "index.production.js",
|
|
8
|
-
"children": [
|
|
9
|
-
{
|
|
10
|
-
"name": "packages",
|
|
11
|
-
"children": [
|
|
12
|
-
{
|
|
13
|
-
"name": "store/build/esm/index.js",
|
|
14
|
-
"uid": "1b85-10"
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
"name": "react-store/src/index.tsx",
|
|
18
|
-
"uid": "1b85-12"
|
|
19
|
-
}
|
|
20
|
-
]
|
|
21
|
-
}
|
|
22
|
-
]
|
|
23
|
-
}
|
|
24
|
-
],
|
|
25
|
-
"isRoot": true
|
|
26
|
-
},
|
|
27
|
-
"nodeParts": {
|
|
28
|
-
"1b85-10": {
|
|
29
|
-
"renderedLength": 1843,
|
|
30
|
-
"gzipLength": 644,
|
|
31
|
-
"brotliLength": 0,
|
|
32
|
-
"mainUid": "1b85-9"
|
|
33
|
-
},
|
|
34
|
-
"1b85-12": {
|
|
35
|
-
"renderedLength": 754,
|
|
36
|
-
"gzipLength": 343,
|
|
37
|
-
"brotliLength": 0,
|
|
38
|
-
"mainUid": "1b85-11"
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
"nodeMetas": {
|
|
42
|
-
"1b85-9": {
|
|
43
|
-
"id": "/packages/store/build/esm/index.js",
|
|
44
|
-
"moduleParts": {
|
|
45
|
-
"index.production.js": "1b85-10"
|
|
46
|
-
},
|
|
47
|
-
"imported": [],
|
|
48
|
-
"importedBy": [
|
|
49
|
-
{
|
|
50
|
-
"uid": "1b85-11"
|
|
51
|
-
}
|
|
52
|
-
]
|
|
53
|
-
},
|
|
54
|
-
"1b85-11": {
|
|
55
|
-
"id": "/packages/react-store/src/index.tsx",
|
|
56
|
-
"moduleParts": {
|
|
57
|
-
"index.production.js": "1b85-12"
|
|
58
|
-
},
|
|
59
|
-
"imported": [
|
|
60
|
-
{
|
|
61
|
-
"uid": "1b85-13"
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
"uid": "1b85-9"
|
|
65
|
-
}
|
|
66
|
-
],
|
|
67
|
-
"importedBy": [],
|
|
68
|
-
"isEntry": true
|
|
69
|
-
},
|
|
70
|
-
"1b85-13": {
|
|
71
|
-
"id": "use-sync-external-store/shim/with-selector",
|
|
72
|
-
"moduleParts": {},
|
|
73
|
-
"imported": [],
|
|
74
|
-
"importedBy": [
|
|
75
|
-
{
|
|
76
|
-
"uid": "1b85-11"
|
|
77
|
-
}
|
|
78
|
-
],
|
|
79
|
-
"isExternal": true
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
"env": {
|
|
83
|
-
"rollup": "2.79.1"
|
|
84
|
-
},
|
|
85
|
-
"options": {
|
|
86
|
-
"gzip": true,
|
|
87
|
-
"brotli": false,
|
|
88
|
-
"sourcemap": false
|
|
89
|
-
}
|
|
90
|
-
}
|
package/build/types/index.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @tanstack/react-store/src/index.tsx
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) TanStack
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
-
*
|
|
9
|
-
* @license MIT
|
|
10
|
-
*/
|
|
11
|
-
import { AnyUpdater, Store } from '@tanstack/store';
|
|
12
|
-
export * from '@tanstack/store';
|
|
13
|
-
|
|
14
|
-
type NoInfer<T> = [T][T extends any ? 0 : never];
|
|
15
|
-
declare function useStore<TState, TSelected = NoInfer<TState>, TUpdater extends AnyUpdater = AnyUpdater>(store: Store<TState, TUpdater>, selector?: (state: NoInfer<TState>) => TSelected): TSelected;
|
|
16
|
-
declare function shallow<T>(objA: T, objB: T): boolean;
|
|
17
|
-
|
|
18
|
-
export { NoInfer, shallow, useStore };
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @tanstack/react-store/src/index.tsx
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) TanStack
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
-
*
|
|
9
|
-
* @license MIT
|
|
10
|
-
*/
|
|
11
|
-
(function (global, factory) {
|
|
12
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('use-sync-external-store/shim/with-selector')) :
|
|
13
|
-
typeof define === 'function' && define.amd ? define(['exports', 'use-sync-external-store/shim/with-selector'], factory) :
|
|
14
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactLoaders = {}, global.withSelector));
|
|
15
|
-
})(this, (function (exports, withSelector) { 'use strict';
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @tanstack/store/src/index.ts
|
|
19
|
-
*
|
|
20
|
-
* Copyright (c) TanStack
|
|
21
|
-
*
|
|
22
|
-
* This source code is licensed under the MIT license found in the
|
|
23
|
-
* LICENSE.md file in the root directory of this source tree.
|
|
24
|
-
*
|
|
25
|
-
* @license MIT
|
|
26
|
-
*/
|
|
27
|
-
class Store {
|
|
28
|
-
listeners = new Set();
|
|
29
|
-
_batching = false;
|
|
30
|
-
_flushing = 0;
|
|
31
|
-
_nextPriority = null;
|
|
32
|
-
constructor(initialState, options) {
|
|
33
|
-
this.state = initialState;
|
|
34
|
-
this.options = options;
|
|
35
|
-
}
|
|
36
|
-
subscribe = listener => {
|
|
37
|
-
this.listeners.add(listener);
|
|
38
|
-
const unsub = this.options?.onSubscribe?.(listener, this);
|
|
39
|
-
return () => {
|
|
40
|
-
this.listeners.delete(listener);
|
|
41
|
-
unsub?.();
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
setState = (updater, opts) => {
|
|
45
|
-
const previous = this.state;
|
|
46
|
-
this.state = this.options?.updateFn ? this.options.updateFn(previous)(updater) : updater(previous);
|
|
47
|
-
const priority = opts?.priority ?? this.options?.defaultPriority ?? 'high';
|
|
48
|
-
if (this._nextPriority === null) {
|
|
49
|
-
this._nextPriority = priority;
|
|
50
|
-
} else if (this._nextPriority === 'high') {
|
|
51
|
-
this._nextPriority = priority;
|
|
52
|
-
} else {
|
|
53
|
-
this._nextPriority = this.options?.defaultPriority ?? 'high';
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Always run onUpdate, regardless of batching
|
|
57
|
-
this.options?.onUpdate?.({
|
|
58
|
-
priority: this._nextPriority
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
// Attempt to flush
|
|
62
|
-
this._flush();
|
|
63
|
-
};
|
|
64
|
-
_flush = () => {
|
|
65
|
-
if (this._batching) return;
|
|
66
|
-
const flushId = ++this._flushing;
|
|
67
|
-
this.listeners.forEach(listener => {
|
|
68
|
-
if (this._flushing !== flushId) return;
|
|
69
|
-
listener({
|
|
70
|
-
priority: this._nextPriority ?? 'high'
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
};
|
|
74
|
-
batch = cb => {
|
|
75
|
-
if (this._batching) return cb();
|
|
76
|
-
this._batching = true;
|
|
77
|
-
cb();
|
|
78
|
-
this._batching = false;
|
|
79
|
-
this._flush();
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function useStore(store, selector = d => d) {
|
|
84
|
-
const slice = withSelector.useSyncExternalStoreWithSelector(store.subscribe, () => store.state, () => store.state, selector, shallow);
|
|
85
|
-
return slice;
|
|
86
|
-
}
|
|
87
|
-
function shallow(objA, objB) {
|
|
88
|
-
if (Object.is(objA, objB)) {
|
|
89
|
-
return true;
|
|
90
|
-
}
|
|
91
|
-
if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
|
|
92
|
-
return false;
|
|
93
|
-
}
|
|
94
|
-
const keysA = Object.keys(objA);
|
|
95
|
-
if (keysA.length !== Object.keys(objB).length) {
|
|
96
|
-
return false;
|
|
97
|
-
}
|
|
98
|
-
for (let i = 0; i < keysA.length; i++) {
|
|
99
|
-
if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !Object.is(objA[keysA[i]], objB[keysA[i]])) {
|
|
100
|
-
return false;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
return true;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
exports.Store = Store;
|
|
107
|
-
exports.shallow = shallow;
|
|
108
|
-
exports.useStore = useStore;
|
|
109
|
-
|
|
110
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
111
|
-
|
|
112
|
-
}));
|
|
113
|
-
//# sourceMappingURL=index.development.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.development.js","sources":["../../../store/build/esm/index.js","../../src/index.tsx"],"sourcesContent":["/**\n * @tanstack/store/src/index.ts\n *\n * Copyright (c) TanStack\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE.md file in the root directory of this source tree.\n *\n * @license MIT\n */\nclass Store {\n listeners = new Set();\n _batching = false;\n _flushing = 0;\n _nextPriority = null;\n constructor(initialState, options) {\n this.state = initialState;\n this.options = options;\n }\n subscribe = listener => {\n this.listeners.add(listener);\n const unsub = this.options?.onSubscribe?.(listener, this);\n return () => {\n this.listeners.delete(listener);\n unsub?.();\n };\n };\n setState = (updater, opts) => {\n const previous = this.state;\n this.state = this.options?.updateFn ? this.options.updateFn(previous)(updater) : updater(previous);\n const priority = opts?.priority ?? this.options?.defaultPriority ?? 'high';\n if (this._nextPriority === null) {\n this._nextPriority = priority;\n } else if (this._nextPriority === 'high') {\n this._nextPriority = priority;\n } else {\n this._nextPriority = this.options?.defaultPriority ?? 'high';\n }\n\n // Always run onUpdate, regardless of batching\n this.options?.onUpdate?.({\n priority: this._nextPriority\n });\n\n // Attempt to flush\n this._flush();\n };\n _flush = () => {\n if (this._batching) return;\n const flushId = ++this._flushing;\n this.listeners.forEach(listener => {\n if (this._flushing !== flushId) return;\n listener({\n priority: this._nextPriority ?? 'high'\n });\n });\n };\n batch = cb => {\n if (this._batching) return cb();\n this._batching = true;\n cb();\n this._batching = false;\n this._flush();\n };\n}\n\nexport { Store };\n//# sourceMappingURL=index.js.map\n","import * as React from 'react'\nimport { AnyUpdater, Store } from '@tanstack/store'\nimport { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector'\n\nexport * from '@tanstack/store'\n\nexport type NoInfer<T> = [T][T extends any ? 0 : never]\n\nexport function useStore<\n TState,\n TSelected = NoInfer<TState>,\n TUpdater extends AnyUpdater = AnyUpdater,\n>(\n store: Store<TState, TUpdater>,\n selector: (state: NoInfer<TState>) => TSelected = (d) => d as any,\n) {\n const slice = useSyncExternalStoreWithSelector(\n store.subscribe,\n () => store.state,\n () => store.state,\n selector,\n shallow,\n )\n\n return slice\n}\n\nexport function shallow<T>(objA: T, objB: T) {\n if (Object.is(objA, objB)) {\n return true\n }\n\n if (\n typeof objA !== 'object' ||\n objA === null ||\n typeof objB !== 'object' ||\n objB === null\n ) {\n return false\n }\n\n const keysA = Object.keys(objA)\n if (keysA.length !== Object.keys(objB).length) {\n return false\n }\n\n for (let i = 0; i < keysA.length; i++) {\n if (\n !Object.prototype.hasOwnProperty.call(objB, keysA[i] as string) ||\n !Object.is(objA[keysA[i] as keyof T], objB[keysA[i] as keyof T])\n ) {\n return false\n }\n }\n return true\n}\n"],"names":["useStore","store","selector","d","slice","useSyncExternalStoreWithSelector","subscribe","state","shallow","objA","objB","Object","is","keysA","keys","length","i","prototype","hasOwnProperty","call"],"mappings":";;;;;;;;;;;;;;;;EAAA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,MAAM,KAAK,CAAC;EACZ,EAAE,SAAS,GAAG,IAAI,GAAG,EAAE,CAAC;EACxB,EAAE,SAAS,GAAG,KAAK,CAAC;EACpB,EAAE,SAAS,GAAG,CAAC,CAAC;EAChB,EAAE,aAAa,GAAG,IAAI,CAAC;EACvB,EAAE,WAAW,CAAC,YAAY,EAAE,OAAO,EAAE;EACrC,IAAI,IAAI,CAAC,KAAK,GAAG,YAAY,CAAC;EAC9B,IAAI,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;EAC3B,GAAG;EACH,EAAE,SAAS,GAAG,QAAQ,IAAI;EAC1B,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;EACjC,IAAI,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,QAAQ,EAAE,IAAI,CAAC,CAAC;EAC9D,IAAI,OAAO,MAAM;EACjB,MAAM,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;EACtC,MAAM,KAAK,IAAI,CAAC;EAChB,KAAK,CAAC;EACN,GAAG,CAAC;EACJ,EAAE,QAAQ,GAAG,CAAC,OAAO,EAAE,IAAI,KAAK;EAChC,IAAI,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC;EAChC,IAAI,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,OAAO,CAA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ACH,IAAI,CAACI,KAAK,CAACG,CAAC,CAAC,CAAY,EAAEN,IAAI,CAACG,KAAK,CAACG,CAAC,CAAC,CAAY,CAAC,EAChE;EACA,MAAA,OAAO,KAAK,CAAA;EACd,KAAA;EACF,GAAA;EACA,EAAA,OAAO,IAAI,CAAA;EACb;;;;;;;;;;;;"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @tanstack/react-store/src/index.tsx
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) TanStack
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
-
*
|
|
9
|
-
* @license MIT
|
|
10
|
-
*/
|
|
11
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("use-sync-external-store/shim/with-selector")):"function"==typeof define&&define.amd?define(["exports","use-sync-external-store/shim/with-selector"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).ReactLoaders={},t.withSelector)}(this,(function(t,e){"use strict";
|
|
12
|
-
/**
|
|
13
|
-
* @tanstack/store/src/index.ts
|
|
14
|
-
*
|
|
15
|
-
* Copyright (c) TanStack
|
|
16
|
-
*
|
|
17
|
-
* This source code is licensed under the MIT license found in the
|
|
18
|
-
* LICENSE.md file in the root directory of this source tree.
|
|
19
|
-
*
|
|
20
|
-
* @license MIT
|
|
21
|
-
*/function i(t,e){if(Object.is(t,e))return!0;if("object"!=typeof t||null===t||"object"!=typeof e||null===e)return!1;const i=Object.keys(t);if(i.length!==Object.keys(e).length)return!1;for(let s=0;s<i.length;s++)if(!Object.prototype.hasOwnProperty.call(e,i[s])||!Object.is(t[i[s]],e[i[s]]))return!1;return!0}t.Store=class{listeners=new Set;_batching=!1;_flushing=0;_nextPriority=null;constructor(t,e){this.state=t,this.options=e}subscribe=t=>{this.listeners.add(t);const e=this.options?.onSubscribe?.(t,this);return()=>{this.listeners.delete(t),e?.()}};setState=(t,e)=>{const i=this.state;this.state=this.options?.updateFn?this.options.updateFn(i)(t):t(i);const s=e?.priority??this.options?.defaultPriority??"high";null===this._nextPriority||"high"===this._nextPriority?this._nextPriority=s:this._nextPriority=this.options?.defaultPriority??"high",this.options?.onUpdate?.({priority:this._nextPriority}),this._flush()};_flush=()=>{if(this._batching)return;const t=++this._flushing;this.listeners.forEach((e=>{this._flushing===t&&e({priority:this._nextPriority??"high"})}))};batch=t=>{if(this._batching)return t();this._batching=!0,t(),this._batching=!1,this._flush()}},t.shallow=i,t.useStore=function(t,s=(t=>t)){return e.useSyncExternalStoreWithSelector(t.subscribe,(()=>t.state),(()=>t.state),s,i)},Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
22
|
-
//# sourceMappingURL=index.production.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.production.js","sources":["../../src/index.tsx","../../../store/build/esm/index.js"],"sourcesContent":["import * as React from 'react'\nimport { AnyUpdater, Store } from '@tanstack/store'\nimport { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector'\n\nexport * from '@tanstack/store'\n\nexport type NoInfer<T> = [T][T extends any ? 0 : never]\n\nexport function useStore<\n TState,\n TSelected = NoInfer<TState>,\n TUpdater extends AnyUpdater = AnyUpdater,\n>(\n store: Store<TState, TUpdater>,\n selector: (state: NoInfer<TState>) => TSelected = (d) => d as any,\n) {\n const slice = useSyncExternalStoreWithSelector(\n store.subscribe,\n () => store.state,\n () => store.state,\n selector,\n shallow,\n )\n\n return slice\n}\n\nexport function shallow<T>(objA: T, objB: T) {\n if (Object.is(objA, objB)) {\n return true\n }\n\n if (\n typeof objA !== 'object' ||\n objA === null ||\n typeof objB !== 'object' ||\n objB === null\n ) {\n return false\n }\n\n const keysA = Object.keys(objA)\n if (keysA.length !== Object.keys(objB).length) {\n return false\n }\n\n for (let i = 0; i < keysA.length; i++) {\n if (\n !Object.prototype.hasOwnProperty.call(objB, keysA[i] as string) ||\n !Object.is(objA[keysA[i] as keyof T], objB[keysA[i] as keyof T])\n ) {\n return false\n }\n }\n return true\n}\n","/**\n * @tanstack/store/src/index.ts\n *\n * Copyright (c) TanStack\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE.md file in the root directory of this source tree.\n *\n * @license MIT\n */\nclass Store {\n listeners = new Set();\n _batching = false;\n _flushing = 0;\n _nextPriority = null;\n constructor(initialState, options) {\n this.state = initialState;\n this.options = options;\n }\n subscribe = listener => {\n this.listeners.add(listener);\n const unsub = this.options?.onSubscribe?.(listener, this);\n return () => {\n this.listeners.delete(listener);\n unsub?.();\n };\n };\n setState = (updater, opts) => {\n const previous = this.state;\n this.state = this.options?.updateFn ? this.options.updateFn(previous)(updater) : updater(previous);\n const priority = opts?.priority ?? this.options?.defaultPriority ?? 'high';\n if (this._nextPriority === null) {\n this._nextPriority = priority;\n } else if (this._nextPriority === 'high') {\n this._nextPriority = priority;\n } else {\n this._nextPriority = this.options?.defaultPriority ?? 'high';\n }\n\n // Always run onUpdate, regardless of batching\n this.options?.onUpdate?.({\n priority: this._nextPriority\n });\n\n // Attempt to flush\n this._flush();\n };\n _flush = () => {\n if (this._batching) return;\n const flushId = ++this._flushing;\n this.listeners.forEach(listener => {\n if (this._flushing !== flushId) return;\n listener({\n priority: this._nextPriority ?? 'high'\n });\n });\n };\n batch = cb => {\n if (this._batching) return cb();\n this._batching = true;\n cb();\n this._batching = false;\n this._flush();\n };\n}\n\nexport { Store };\n//# sourceMappingURL=index.js.map\n"],"names":["shallow","objA","objB","Object","is","keysA","keys","length","i","prototype","hasOwnProperty","call","listeners","Set","_batching","_flushing","_nextPriority","constructor","initialState","options","this","state","subscribe","listener","add","unsub","onSubscribe","delete","setState","updater","opts","previous","updateFn","priority","defaultPriority","onUpdate","_flush","flushId","forEach","batch","cb","store","selector","d","useSyncExternalStoreWithSelector"],"mappings":";;;;;;;;;;;;;;;;;;;;KA2BO,SAASA,EAAWC,EAASC,GAClC,GAAIC,OAAOC,GAAGH,EAAMC,GACl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