@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.
@@ -6,7 +6,11 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
 
8
8
  class MockStore {
9
- dispatch(data) {// do nothing
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","data","removeAllListeners","subscribe","listener"],"sources":["MockStore.ts"],"sourcesContent":["import { MonoStore, StoreSubscription } from './types';\n\nexport default class MockStore<T> implements MonoStore<T> {\n\n dispatch(data: T): void {\n // do nothing\n }\n\n removeAllListeners(): void {\n // do nothing\n }\n\n subscribe(listener: (data: T) => void): StoreSubscription {\n return () => void 0;\n }\n\n};\n"],"mappings":";;;;;;;AAEe,MAAMA,SAAN,CAA2C;EAEtDC,QAAQ,CAACC,IAAD,EAAgB,CACpB;EACH;;EAEDC,kBAAkB,GAAS,CACvB;EACH;;EAEDC,SAAS,CAACC,QAAD,EAAiD;IACtD,OAAO,MAAM,KAAK,CAAlB;EACH;;AAZqD;;;AAczD"}
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(initialData) {
16
- _defineProperty(this, "data", void 0);
15
+ constructor(initialState) {
16
+ _defineProperty(this, "state", void 0);
17
17
 
18
18
  _defineProperty(this, "listeners", []);
19
19
 
20
- this.data = initialData;
20
+ this.state = initialState;
21
21
  }
22
22
 
23
- subscribe(listener) {
24
- this.listeners.push(listener);
25
- return () => {
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.data = data;
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(data);
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","initialData","data","subscribe","listener","listeners","push","index","indexOf","splice","dispatch","id","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<T> implements MonoStore<T> {\n\n private data: T;\n\n private listeners: Array<(data: T) => void> = [];\n\n constructor(initialData: T) {\n this.data = initialData;\n }\n\n subscribe(listener: (data: T) => 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 dispatch(data: T): void {\n // Do not dispatch if data ref is equal\n if (refEqual(this.data, data)) {\n return;\n }\n\n this.data = data;\n for (const id in this.listeners) {\n const listener = this.listeners[id];\n listener?.(data);\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,WAAD,EAAiB;IAAA;;IAAA,mCAFkB,EAElB;;IACxB,KAAKC,IAAL,GAAYD,WAAZ;EACH;;EAEDE,SAAS,CAACC,QAAD,EAAiD;IACtD,KAAKC,SAAL,CAAeC,IAAf,CAAoBF,QAApB;IAEA,OAAO,MAAM;MACT,MAAMG,KAAK,GAAG,KAAKF,SAAL,CAAeG,OAAf,CAAuBJ,QAAvB,CAAd;MACA,KAAKC,SAAL,CAAeI,MAAf,CAAsBF,KAAtB,EAA6B,CAA7B;IACH,CAHD;EAIH;;EAEDG,QAAQ,CAACR,IAAD,EAAgB;IACpB;IACA,IAAIN,QAAQ,CAAC,KAAKM,IAAN,EAAYA,IAAZ,CAAZ,EAA+B;MAC3B;IACH;;IAED,KAAKA,IAAL,GAAYA,IAAZ;;IACA,KAAK,MAAMS,EAAX,IAAiB,KAAKN,SAAtB,EAAiC;MAC7B,MAAMD,QAAQ,GAAG,KAAKC,SAAL,CAAeM,EAAf,CAAjB;MACAP,QAAQ,SAAR,IAAAA,QAAQ,WAAR,YAAAA,QAAQ,CAAGF,IAAH,CAAR;IACH;EACJ;;EAEDU,kBAAkB,GAAS;IACvB,KAAKP,SAAL,CAAeI,MAAf,CAAsB,CAAtB,EAAyB,KAAKJ,SAAL,CAAeQ,MAAxC;EACH;;AAlCuD;;;AAoC3D"}
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<T> {\n dispatch: (data: T) => void;\n subscribe: (listener: (data: T) => void) => StoreSubscription;\n removeAllListeners: () => void;\n}\n"],"mappings":""}
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,5 +1,9 @@
1
1
  export default class MockStore {
2
- dispatch(data) {// do nothing
2
+ dispatch(state) {// do nothing
3
+ }
4
+
5
+ getState() {
6
+ throw new Error('stub!');
3
7
  }
4
8
 
5
9
  removeAllListeners() {// do nothing
@@ -1 +1 @@
1
- {"version":3,"names":["MockStore","dispatch","data","removeAllListeners","subscribe","listener"],"sources":["MockStore.ts"],"sourcesContent":["import { MonoStore, StoreSubscription } from './types';\n\nexport default class MockStore<T> implements MonoStore<T> {\n\n dispatch(data: T): void {\n // do nothing\n }\n\n removeAllListeners(): void {\n // do nothing\n }\n\n subscribe(listener: (data: T) => void): StoreSubscription {\n return () => void 0;\n }\n\n};\n"],"mappings":"AAEA,eAAe,MAAMA,SAAN,CAA2C;EAEtDC,QAAQ,CAACC,IAAD,EAAgB,CACpB;EACH;;EAEDC,kBAAkB,GAAS,CACvB;EACH;;EAEDC,SAAS,CAACC,QAAD,EAAiD;IACtD,OAAO,MAAM,KAAK,CAAlB;EACH;;AAZqD;AAczD"}
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(initialData) {
9
- _defineProperty(this, "data", void 0);
8
+ constructor(initialState) {
9
+ _defineProperty(this, "state", void 0);
10
10
 
11
11
  _defineProperty(this, "listeners", []);
12
12
 
13
- this.data = initialData;
13
+ this.state = initialState;
14
14
  }
15
15
 
16
- subscribe(listener) {
17
- this.listeners.push(listener);
18
- return () => {
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.data = data;
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(data);
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","initialData","data","subscribe","listener","listeners","push","index","indexOf","splice","dispatch","id","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<T> implements MonoStore<T> {\n\n private data: T;\n\n private listeners: Array<(data: T) => void> = [];\n\n constructor(initialData: T) {\n this.data = initialData;\n }\n\n subscribe(listener: (data: T) => 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 dispatch(data: T): void {\n // Do not dispatch if data ref is equal\n if (refEqual(this.data, data)) {\n return;\n }\n\n this.data = data;\n for (const id in this.listeners) {\n const listener = this.listeners[id];\n listener?.(data);\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,WAAD,EAAiB;IAAA;;IAAA,mCAFkB,EAElB;;IACxB,KAAKC,IAAL,GAAYD,WAAZ;EACH;;EAEDE,SAAS,CAACC,QAAD,EAAiD;IACtD,KAAKC,SAAL,CAAeC,IAAf,CAAoBF,QAApB;IAEA,OAAO,MAAM;MACT,MAAMG,KAAK,GAAG,KAAKF,SAAL,CAAeG,OAAf,CAAuBJ,QAAvB,CAAd;MACA,KAAKC,SAAL,CAAeI,MAAf,CAAsBF,KAAtB,EAA6B,CAA7B;IACH,CAHD;EAIH;;EAEDG,QAAQ,CAACR,IAAD,EAAgB;IACpB;IACA,IAAIN,QAAQ,CAAC,KAAKM,IAAN,EAAYA,IAAZ,CAAZ,EAA+B;MAC3B;IACH;;IAED,KAAKA,IAAL,GAAYA,IAAZ;;IACA,KAAK,MAAMS,EAAX,IAAiB,KAAKN,SAAtB,EAAiC;MAC7B,MAAMD,QAAQ,GAAG,KAAKC,SAAL,CAAeM,EAAf,CAAjB;MACAP,QAAQ,SAAR,IAAAA,QAAQ,WAAR,YAAAA,QAAQ,CAAGF,IAAH,CAAR;IACH;EACJ;;EAEDU,kBAAkB,GAAS;IACvB,KAAKP,SAAL,CAAeI,MAAf,CAAsB,CAAtB,EAAyB,KAAKJ,SAAL,CAAeQ,MAAxC;EACH;;AAlCuD;AAoC3D"}
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<T> {\n dispatch: (data: T) => void;\n subscribe: (listener: (data: T) => void) => StoreSubscription;\n removeAllListeners: () => void;\n}\n"],"mappings":""}
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<T> implements MonoStore<T> {
3
- dispatch(data: T): void;
2
+ export default class MockStore<S> implements MonoStore<S> {
3
+ dispatch(state: S): void;
4
+ getState(): S;
4
5
  removeAllListeners(): void;
5
- subscribe(listener: (data: T) => void): StoreSubscription;
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<T> implements MonoStore<T> {
3
- private data;
2
+ export default class SimpleStore<S> implements MonoStore<S> {
3
+ private state;
4
4
  private listeners;
5
- constructor(initialData: T);
6
- subscribe(listener: (data: T) => void): StoreSubscription;
7
- dispatch(data: T): void;
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<T> {
5
- dispatch: (data: T) => void;
6
- subscribe: (listener: (data: T) => void) => StoreSubscription;
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.22",
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": "e97185cf56e1f51817e29a7d1b7e43bcf8ef0342"
70
+ "gitHead": "8b3569226ab4fc9c5812084f850461c9beffe496"
71
71
  }
@@ -1,16 +1,20 @@
1
1
  import { MonoStore, StoreSubscription } from './types';
2
2
 
3
- export default class MockStore<T> implements MonoStore<T> {
3
+ export default class MockStore<S> implements MonoStore<S> {
4
4
 
5
- dispatch(data: T): void {
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: (data: T) => void): StoreSubscription {
17
+ subscribe(listener: (state: S) => void): StoreSubscription {
14
18
  return () => void 0;
15
19
  }
16
20
 
@@ -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<T> implements MonoStore<T> {
7
+ export default class SimpleStore<S> implements MonoStore<S> {
8
8
 
9
- private data: T;
9
+ private state: S;
10
10
 
11
- private listeners: Array<(data: T) => void> = [];
11
+ private listeners: Array<(state: S) => void> = [];
12
12
 
13
- constructor(initialData: T) {
14
- this.data = initialData;
13
+ constructor(initialState: S) {
14
+ this.state = initialState;
15
15
  }
16
16
 
17
- subscribe(listener: (data: T) => void): StoreSubscription {
18
- this.listeners.push(listener);
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.data = data;
23
+ this.state = state;
33
24
  for (const id in this.listeners) {
34
25
  const listener = this.listeners[id];
35
- listener?.(data);
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
  }
@@ -2,8 +2,9 @@ export interface StoreSubscription {
2
2
  (): void;
3
3
  }
4
4
 
5
- export interface MonoStore<T> {
6
- dispatch: (data: T) => void;
7
- subscribe: (listener: (data: T) => void) => StoreSubscription;
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
  }