@fountain-ui/core 2.0.0-beta.22 → 2.0.0-beta.23
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/build/commonjs/store/MockStore.js +5 -1
- package/build/commonjs/store/MockStore.js.map +1 -1
- package/build/commonjs/store/SimpleStore.js +20 -16
- package/build/commonjs/store/SimpleStore.js.map +1 -1
- package/build/commonjs/store/types.js.map +1 -1
- package/build/module/store/MockStore.js +5 -1
- package/build/module/store/MockStore.js.map +1 -1
- package/build/module/store/SimpleStore.js +20 -16
- package/build/module/store/SimpleStore.js.map +1 -1
- package/build/module/store/types.js.map +1 -1
- package/build/typescript/store/MockStore.d.ts +4 -3
- package/build/typescript/store/SimpleStore.d.ts +6 -5
- package/build/typescript/store/types.d.ts +4 -3
- package/package.json +2 -2
- package/src/store/MockStore.ts +7 -3
- package/src/store/SimpleStore.ts +23 -19
- package/src/store/types.ts +4 -3
|
@@ -6,7 +6,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
8
|
class MockStore {
|
|
9
|
-
dispatch(
|
|
9
|
+
dispatch(state) {// do nothing
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
getState() {
|
|
13
|
+
throw new Error('stub!');
|
|
10
14
|
}
|
|
11
15
|
|
|
12
16
|
removeAllListeners() {// do nothing
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["MockStore","dispatch","
|
|
1
|
+
{"version":3,"names":["MockStore","dispatch","state","getState","Error","removeAllListeners","subscribe","listener"],"sources":["MockStore.ts"],"sourcesContent":["import { MonoStore, StoreSubscription } from './types';\n\nexport default class MockStore<S> implements MonoStore<S> {\n\n dispatch(state: S): void {\n // do nothing\n }\n\n getState(): S {\n throw new Error('stub!');\n }\n\n removeAllListeners(): void {\n // do nothing\n }\n\n subscribe(listener: (state: S) => void): StoreSubscription {\n return () => void 0;\n }\n\n};\n"],"mappings":";;;;;;;AAEe,MAAMA,SAAN,CAA2C;EAEtDC,QAAQ,CAACC,KAAD,EAAiB,CACrB;EACH;;EAEDC,QAAQ,GAAM;IACV,MAAM,IAAIC,KAAJ,CAAU,OAAV,CAAN;EACH;;EAEDC,kBAAkB,GAAS,CACvB;EACH;;EAEDC,SAAS,CAACC,QAAD,EAAkD;IACvD,OAAO,MAAM,KAAK,CAAlB;EACH;;AAhBqD;;;AAkBzD"}
|
|
@@ -12,36 +12,40 @@ function refEqual(a, b) {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
class SimpleStore {
|
|
15
|
-
constructor(
|
|
16
|
-
_defineProperty(this, "
|
|
15
|
+
constructor(initialState) {
|
|
16
|
+
_defineProperty(this, "state", void 0);
|
|
17
17
|
|
|
18
18
|
_defineProperty(this, "listeners", []);
|
|
19
19
|
|
|
20
|
-
this.
|
|
20
|
+
this.state = initialState;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const index = this.listeners.indexOf(listener);
|
|
27
|
-
this.listeners.splice(index, 1);
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
dispatch(data) {
|
|
32
|
-
// Do not dispatch if data ref is equal
|
|
33
|
-
if (refEqual(this.data, data)) {
|
|
23
|
+
dispatch(state) {
|
|
24
|
+
// Do not dispatch if state ref is equal
|
|
25
|
+
if (refEqual(this.state, state)) {
|
|
34
26
|
return;
|
|
35
27
|
}
|
|
36
28
|
|
|
37
|
-
this.
|
|
29
|
+
this.state = state;
|
|
38
30
|
|
|
39
31
|
for (const id in this.listeners) {
|
|
40
32
|
const listener = this.listeners[id];
|
|
41
|
-
listener === null || listener === void 0 ? void 0 : listener(
|
|
33
|
+
listener === null || listener === void 0 ? void 0 : listener(state);
|
|
42
34
|
}
|
|
43
35
|
}
|
|
44
36
|
|
|
37
|
+
getState() {
|
|
38
|
+
return this.state;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
subscribe(listener) {
|
|
42
|
+
this.listeners.push(listener);
|
|
43
|
+
return () => {
|
|
44
|
+
const index = this.listeners.indexOf(listener);
|
|
45
|
+
this.listeners.splice(index, 1);
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
45
49
|
removeAllListeners() {
|
|
46
50
|
this.listeners.splice(0, this.listeners.length);
|
|
47
51
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["refEqual","a","b","SimpleStore","constructor","
|
|
1
|
+
{"version":3,"names":["refEqual","a","b","SimpleStore","constructor","initialState","state","dispatch","id","listeners","listener","getState","subscribe","push","index","indexOf","splice","removeAllListeners","length"],"sources":["SimpleStore.ts"],"sourcesContent":["import { MonoStore, StoreSubscription } from './types';\n\nfunction refEqual(a: any, b: any): boolean {\n return a === b;\n}\n\nexport default class SimpleStore<S> implements MonoStore<S> {\n\n private state: S;\n\n private listeners: Array<(state: S) => void> = [];\n\n constructor(initialState: S) {\n this.state = initialState;\n }\n\n dispatch(state: S): void {\n // Do not dispatch if state ref is equal\n if (refEqual(this.state, state)) {\n return;\n }\n\n this.state = state;\n for (const id in this.listeners) {\n const listener = this.listeners[id];\n listener?.(state);\n }\n }\n\n getState(): S {\n return this.state;\n }\n\n subscribe(listener: (state: S) => void): StoreSubscription {\n this.listeners.push(listener);\n\n return () => {\n const index = this.listeners.indexOf(listener);\n this.listeners.splice(index, 1);\n };\n }\n\n removeAllListeners(): void {\n this.listeners.splice(0, this.listeners.length);\n }\n\n};\n"],"mappings":";;;;;;;;;AAEA,SAASA,QAAT,CAAkBC,CAAlB,EAA0BC,CAA1B,EAA2C;EACvC,OAAOD,CAAC,KAAKC,CAAb;AACH;;AAEc,MAAMC,WAAN,CAA6C;EAMxDC,WAAW,CAACC,YAAD,EAAkB;IAAA;;IAAA,mCAFkB,EAElB;;IACzB,KAAKC,KAAL,GAAaD,YAAb;EACH;;EAEDE,QAAQ,CAACD,KAAD,EAAiB;IACrB;IACA,IAAIN,QAAQ,CAAC,KAAKM,KAAN,EAAaA,KAAb,CAAZ,EAAiC;MAC7B;IACH;;IAED,KAAKA,KAAL,GAAaA,KAAb;;IACA,KAAK,MAAME,EAAX,IAAiB,KAAKC,SAAtB,EAAiC;MAC7B,MAAMC,QAAQ,GAAG,KAAKD,SAAL,CAAeD,EAAf,CAAjB;MACAE,QAAQ,SAAR,IAAAA,QAAQ,WAAR,YAAAA,QAAQ,CAAGJ,KAAH,CAAR;IACH;EACJ;;EAEDK,QAAQ,GAAM;IACV,OAAO,KAAKL,KAAZ;EACH;;EAEDM,SAAS,CAACF,QAAD,EAAkD;IACvD,KAAKD,SAAL,CAAeI,IAAf,CAAoBH,QAApB;IAEA,OAAO,MAAM;MACT,MAAMI,KAAK,GAAG,KAAKL,SAAL,CAAeM,OAAf,CAAuBL,QAAvB,CAAd;MACA,KAAKD,SAAL,CAAeO,MAAf,CAAsBF,KAAtB,EAA6B,CAA7B;IACH,CAHD;EAIH;;EAEDG,kBAAkB,GAAS;IACvB,KAAKR,SAAL,CAAeO,MAAf,CAAsB,CAAtB,EAAyB,KAAKP,SAAL,CAAeS,MAAxC;EACH;;AAtCuD;;;AAwC3D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["export interface StoreSubscription {\n (): void;\n}\n\nexport interface MonoStore<
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["export interface StoreSubscription {\n (): void;\n}\n\nexport interface MonoStore<S> {\n dispatch: (state: S) => void;\n getState: () => S;\n subscribe: (listener: (state: S) => void) => StoreSubscription;\n removeAllListeners: () => void;\n}\n"],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["MockStore","dispatch","
|
|
1
|
+
{"version":3,"names":["MockStore","dispatch","state","getState","Error","removeAllListeners","subscribe","listener"],"sources":["MockStore.ts"],"sourcesContent":["import { MonoStore, StoreSubscription } from './types';\n\nexport default class MockStore<S> implements MonoStore<S> {\n\n dispatch(state: S): void {\n // do nothing\n }\n\n getState(): S {\n throw new Error('stub!');\n }\n\n removeAllListeners(): void {\n // do nothing\n }\n\n subscribe(listener: (state: S) => void): StoreSubscription {\n return () => void 0;\n }\n\n};\n"],"mappings":"AAEA,eAAe,MAAMA,SAAN,CAA2C;EAEtDC,QAAQ,CAACC,KAAD,EAAiB,CACrB;EACH;;EAEDC,QAAQ,GAAM;IACV,MAAM,IAAIC,KAAJ,CAAU,OAAV,CAAN;EACH;;EAEDC,kBAAkB,GAAS,CACvB;EACH;;EAEDC,SAAS,CAACC,QAAD,EAAkD;IACvD,OAAO,MAAM,KAAK,CAAlB;EACH;;AAhBqD;AAkBzD"}
|
|
@@ -5,36 +5,40 @@ function refEqual(a, b) {
|
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
export default class SimpleStore {
|
|
8
|
-
constructor(
|
|
9
|
-
_defineProperty(this, "
|
|
8
|
+
constructor(initialState) {
|
|
9
|
+
_defineProperty(this, "state", void 0);
|
|
10
10
|
|
|
11
11
|
_defineProperty(this, "listeners", []);
|
|
12
12
|
|
|
13
|
-
this.
|
|
13
|
+
this.state = initialState;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const index = this.listeners.indexOf(listener);
|
|
20
|
-
this.listeners.splice(index, 1);
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
dispatch(data) {
|
|
25
|
-
// Do not dispatch if data ref is equal
|
|
26
|
-
if (refEqual(this.data, data)) {
|
|
16
|
+
dispatch(state) {
|
|
17
|
+
// Do not dispatch if state ref is equal
|
|
18
|
+
if (refEqual(this.state, state)) {
|
|
27
19
|
return;
|
|
28
20
|
}
|
|
29
21
|
|
|
30
|
-
this.
|
|
22
|
+
this.state = state;
|
|
31
23
|
|
|
32
24
|
for (const id in this.listeners) {
|
|
33
25
|
const listener = this.listeners[id];
|
|
34
|
-
listener === null || listener === void 0 ? void 0 : listener(
|
|
26
|
+
listener === null || listener === void 0 ? void 0 : listener(state);
|
|
35
27
|
}
|
|
36
28
|
}
|
|
37
29
|
|
|
30
|
+
getState() {
|
|
31
|
+
return this.state;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
subscribe(listener) {
|
|
35
|
+
this.listeners.push(listener);
|
|
36
|
+
return () => {
|
|
37
|
+
const index = this.listeners.indexOf(listener);
|
|
38
|
+
this.listeners.splice(index, 1);
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
38
42
|
removeAllListeners() {
|
|
39
43
|
this.listeners.splice(0, this.listeners.length);
|
|
40
44
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["refEqual","a","b","SimpleStore","constructor","
|
|
1
|
+
{"version":3,"names":["refEqual","a","b","SimpleStore","constructor","initialState","state","dispatch","id","listeners","listener","getState","subscribe","push","index","indexOf","splice","removeAllListeners","length"],"sources":["SimpleStore.ts"],"sourcesContent":["import { MonoStore, StoreSubscription } from './types';\n\nfunction refEqual(a: any, b: any): boolean {\n return a === b;\n}\n\nexport default class SimpleStore<S> implements MonoStore<S> {\n\n private state: S;\n\n private listeners: Array<(state: S) => void> = [];\n\n constructor(initialState: S) {\n this.state = initialState;\n }\n\n dispatch(state: S): void {\n // Do not dispatch if state ref is equal\n if (refEqual(this.state, state)) {\n return;\n }\n\n this.state = state;\n for (const id in this.listeners) {\n const listener = this.listeners[id];\n listener?.(state);\n }\n }\n\n getState(): S {\n return this.state;\n }\n\n subscribe(listener: (state: S) => void): StoreSubscription {\n this.listeners.push(listener);\n\n return () => {\n const index = this.listeners.indexOf(listener);\n this.listeners.splice(index, 1);\n };\n }\n\n removeAllListeners(): void {\n this.listeners.splice(0, this.listeners.length);\n }\n\n};\n"],"mappings":";;AAEA,SAASA,QAAT,CAAkBC,CAAlB,EAA0BC,CAA1B,EAA2C;EACvC,OAAOD,CAAC,KAAKC,CAAb;AACH;;AAED,eAAe,MAAMC,WAAN,CAA6C;EAMxDC,WAAW,CAACC,YAAD,EAAkB;IAAA;;IAAA,mCAFkB,EAElB;;IACzB,KAAKC,KAAL,GAAaD,YAAb;EACH;;EAEDE,QAAQ,CAACD,KAAD,EAAiB;IACrB;IACA,IAAIN,QAAQ,CAAC,KAAKM,KAAN,EAAaA,KAAb,CAAZ,EAAiC;MAC7B;IACH;;IAED,KAAKA,KAAL,GAAaA,KAAb;;IACA,KAAK,MAAME,EAAX,IAAiB,KAAKC,SAAtB,EAAiC;MAC7B,MAAMC,QAAQ,GAAG,KAAKD,SAAL,CAAeD,EAAf,CAAjB;MACAE,QAAQ,SAAR,IAAAA,QAAQ,WAAR,YAAAA,QAAQ,CAAGJ,KAAH,CAAR;IACH;EACJ;;EAEDK,QAAQ,GAAM;IACV,OAAO,KAAKL,KAAZ;EACH;;EAEDM,SAAS,CAACF,QAAD,EAAkD;IACvD,KAAKD,SAAL,CAAeI,IAAf,CAAoBH,QAApB;IAEA,OAAO,MAAM;MACT,MAAMI,KAAK,GAAG,KAAKL,SAAL,CAAeM,OAAf,CAAuBL,QAAvB,CAAd;MACA,KAAKD,SAAL,CAAeO,MAAf,CAAsBF,KAAtB,EAA6B,CAA7B;IACH,CAHD;EAIH;;EAEDG,kBAAkB,GAAS;IACvB,KAAKR,SAAL,CAAeO,MAAf,CAAsB,CAAtB,EAAyB,KAAKP,SAAL,CAAeS,MAAxC;EACH;;AAtCuD;AAwC3D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["export interface StoreSubscription {\n (): void;\n}\n\nexport interface MonoStore<
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["export interface StoreSubscription {\n (): void;\n}\n\nexport interface MonoStore<S> {\n dispatch: (state: S) => void;\n getState: () => S;\n subscribe: (listener: (state: S) => void) => StoreSubscription;\n removeAllListeners: () => void;\n}\n"],"mappings":""}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { MonoStore, StoreSubscription } from './types';
|
|
2
|
-
export default class MockStore<
|
|
3
|
-
dispatch(
|
|
2
|
+
export default class MockStore<S> implements MonoStore<S> {
|
|
3
|
+
dispatch(state: S): void;
|
|
4
|
+
getState(): S;
|
|
4
5
|
removeAllListeners(): void;
|
|
5
|
-
subscribe(listener: (
|
|
6
|
+
subscribe(listener: (state: S) => void): StoreSubscription;
|
|
6
7
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { MonoStore, StoreSubscription } from './types';
|
|
2
|
-
export default class SimpleStore<
|
|
3
|
-
private
|
|
2
|
+
export default class SimpleStore<S> implements MonoStore<S> {
|
|
3
|
+
private state;
|
|
4
4
|
private listeners;
|
|
5
|
-
constructor(
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
constructor(initialState: S);
|
|
6
|
+
dispatch(state: S): void;
|
|
7
|
+
getState(): S;
|
|
8
|
+
subscribe(listener: (state: S) => void): StoreSubscription;
|
|
8
9
|
removeAllListeners(): void;
|
|
9
10
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export interface StoreSubscription {
|
|
2
2
|
(): void;
|
|
3
3
|
}
|
|
4
|
-
export interface MonoStore<
|
|
5
|
-
dispatch: (
|
|
6
|
-
|
|
4
|
+
export interface MonoStore<S> {
|
|
5
|
+
dispatch: (state: S) => void;
|
|
6
|
+
getState: () => S;
|
|
7
|
+
subscribe: (listener: (state: S) => void) => StoreSubscription;
|
|
7
8
|
removeAllListeners: () => void;
|
|
8
9
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fountain-ui/core",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.23",
|
|
4
4
|
"author": "Fountain-UI Team",
|
|
5
5
|
"description": "React components that implement Tappytoon's Fountain Design.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"publishConfig": {
|
|
68
68
|
"access": "public"
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "8b3569226ab4fc9c5812084f850461c9beffe496"
|
|
71
71
|
}
|
package/src/store/MockStore.ts
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import { MonoStore, StoreSubscription } from './types';
|
|
2
2
|
|
|
3
|
-
export default class MockStore<
|
|
3
|
+
export default class MockStore<S> implements MonoStore<S> {
|
|
4
4
|
|
|
5
|
-
dispatch(
|
|
5
|
+
dispatch(state: S): void {
|
|
6
6
|
// do nothing
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
getState(): S {
|
|
10
|
+
throw new Error('stub!');
|
|
11
|
+
}
|
|
12
|
+
|
|
9
13
|
removeAllListeners(): void {
|
|
10
14
|
// do nothing
|
|
11
15
|
}
|
|
12
16
|
|
|
13
|
-
subscribe(listener: (
|
|
17
|
+
subscribe(listener: (state: S) => void): StoreSubscription {
|
|
14
18
|
return () => void 0;
|
|
15
19
|
}
|
|
16
20
|
|
package/src/store/SimpleStore.ts
CHANGED
|
@@ -4,38 +4,42 @@ function refEqual(a: any, b: any): boolean {
|
|
|
4
4
|
return a === b;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
export default class SimpleStore<
|
|
7
|
+
export default class SimpleStore<S> implements MonoStore<S> {
|
|
8
8
|
|
|
9
|
-
private
|
|
9
|
+
private state: S;
|
|
10
10
|
|
|
11
|
-
private listeners: Array<(
|
|
11
|
+
private listeners: Array<(state: S) => void> = [];
|
|
12
12
|
|
|
13
|
-
constructor(
|
|
14
|
-
this.
|
|
13
|
+
constructor(initialState: S) {
|
|
14
|
+
this.state = initialState;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return () => {
|
|
21
|
-
const index = this.listeners.indexOf(listener);
|
|
22
|
-
this.listeners.splice(index, 1);
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
dispatch(data: T): void {
|
|
27
|
-
// Do not dispatch if data ref is equal
|
|
28
|
-
if (refEqual(this.data, data)) {
|
|
17
|
+
dispatch(state: S): void {
|
|
18
|
+
// Do not dispatch if state ref is equal
|
|
19
|
+
if (refEqual(this.state, state)) {
|
|
29
20
|
return;
|
|
30
21
|
}
|
|
31
22
|
|
|
32
|
-
this.
|
|
23
|
+
this.state = state;
|
|
33
24
|
for (const id in this.listeners) {
|
|
34
25
|
const listener = this.listeners[id];
|
|
35
|
-
listener?.(
|
|
26
|
+
listener?.(state);
|
|
36
27
|
}
|
|
37
28
|
}
|
|
38
29
|
|
|
30
|
+
getState(): S {
|
|
31
|
+
return this.state;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
subscribe(listener: (state: S) => void): StoreSubscription {
|
|
35
|
+
this.listeners.push(listener);
|
|
36
|
+
|
|
37
|
+
return () => {
|
|
38
|
+
const index = this.listeners.indexOf(listener);
|
|
39
|
+
this.listeners.splice(index, 1);
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
39
43
|
removeAllListeners(): void {
|
|
40
44
|
this.listeners.splice(0, this.listeners.length);
|
|
41
45
|
}
|
package/src/store/types.ts
CHANGED
|
@@ -2,8 +2,9 @@ export interface StoreSubscription {
|
|
|
2
2
|
(): void;
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
-
export interface MonoStore<
|
|
6
|
-
dispatch: (
|
|
7
|
-
|
|
5
|
+
export interface MonoStore<S> {
|
|
6
|
+
dispatch: (state: S) => void;
|
|
7
|
+
getState: () => S;
|
|
8
|
+
subscribe: (listener: (state: S) => void) => StoreSubscription;
|
|
8
9
|
removeAllListeners: () => void;
|
|
9
10
|
}
|