@figliolia/galena 1.0.1 → 2.0.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/README.md CHANGED
@@ -54,7 +54,7 @@ Creating units of state using `AppState.composeState()` will scope your new unit
54
54
  // BusinessLogic.ts
55
55
  import { AppState } from "./AppState.ts";
56
56
 
57
- const subscription = AppState.subscribe("navigation", navigationState => {
57
+ const subscription = AppState.subscribe("navigation", state => {
58
58
  // React to changes to Navigation state
59
59
  });
60
60
 
@@ -531,4 +531,5 @@ As the application scales with more state updates and connected components, the
531
531
  ### Support for Frontend Frameworks!
532
532
  `Galena` provides bindings for React through [react-galena](https://github.com/alexfigliolia/react-galena). This package provides factories for generating HOC's and hooks from your Galena instances and units of State!
533
533
 
534
-
534
+ #### Demo Application
535
+ To see some basic usage using Galena with React, please check out this [Example App](https://github.com/alexfigliolia/galena-quick-start)
@@ -26,32 +26,32 @@ import { State } from "./State";
26
26
  * import { AppState } from "./AppState";
27
27
  *
28
28
  * AppState.subscribe(appState => {
29
- * const navState = appState.get("navigation");
30
- * const { currentRoute } = navState.state;
31
- * // do something with state changes!
29
+ * const navState = appState.get("navigation");
30
+ * const { currentRoute } = navState.state;
31
+ * // do something with state changes!
32
32
  * });
33
33
  * ```
34
34
  * #### Using the State Instance
35
35
  * ```typescript
36
36
  * NavigationState.subscribe(navigation => {
37
- * const { currentRoute } = navigation.state
38
- * // do something with state changes!
37
+ * const { currentRoute } = navigation
38
+ * // do something with state changes!
39
39
  * });
40
40
  * ```
41
41
  *
42
42
  * #### Using Global Subscriptions
43
43
  * ```typescript
44
- * NavigationState.subscribeAll(galenaInstance => {
45
- * const { currentRoute } = galenaInstance.get("navigation").state
46
- * // do something with state changes!
44
+ * NavigationState.subscribeAll(nextState => {
45
+ * const { currentRoute } = nextState.navigation
46
+ * // do something with state changes!
47
47
  * });
48
48
  * ```
49
49
  *
50
50
  * ### Mutating State
51
51
  * ```typescript
52
52
  * NavigationState.update(state => {
53
- * state.currentRoute = "/profile";
54
- * // You can mutate state without creating new objects!
53
+ * state.currentRoute = "/profile";
54
+ * // You can mutate state without creating new objects!
55
55
  * });
56
56
  * ```
57
57
  */
@@ -113,7 +113,7 @@ export declare class Galena<T extends Record<string, State<any>> = Record<string
113
113
  * subscription, call `Galena.unsubscribe()` with the ID returned
114
114
  * by this method
115
115
  */
116
- subscribe<K extends keyof T>(name: K, mutation: Parameters<T[K]["subscribe"]>["0"]): string;
116
+ subscribe<K extends keyof T>(name: K, callback: Parameters<T[K]["subscribe"]>["0"]): string;
117
117
  /**
118
118
  * Unsubscribe
119
119
  *
@@ -132,7 +132,7 @@ export declare class Galena<T extends Record<string, State<any>> = Record<string
132
132
  * subscription, call `Galena.unsubscribeAll()` with the ID
133
133
  * returned
134
134
  */
135
- subscribeAll(callback: (state: Galena<T>) => void): string;
135
+ subscribeAll(callback: (nextState: T) => void): string;
136
136
  /**
137
137
  * Unsubscribe
138
138
  *
@@ -29,32 +29,32 @@ const State_1 = require("./State");
29
29
  * import { AppState } from "./AppState";
30
30
  *
31
31
  * AppState.subscribe(appState => {
32
- * const navState = appState.get("navigation");
33
- * const { currentRoute } = navState.state;
34
- * // do something with state changes!
32
+ * const navState = appState.get("navigation");
33
+ * const { currentRoute } = navState.state;
34
+ * // do something with state changes!
35
35
  * });
36
36
  * ```
37
37
  * #### Using the State Instance
38
38
  * ```typescript
39
39
  * NavigationState.subscribe(navigation => {
40
- * const { currentRoute } = navigation.state
41
- * // do something with state changes!
40
+ * const { currentRoute } = navigation
41
+ * // do something with state changes!
42
42
  * });
43
43
  * ```
44
44
  *
45
45
  * #### Using Global Subscriptions
46
46
  * ```typescript
47
- * NavigationState.subscribeAll(galenaInstance => {
48
- * const { currentRoute } = galenaInstance.get("navigation").state
49
- * // do something with state changes!
47
+ * NavigationState.subscribeAll(nextState => {
48
+ * const { currentRoute } = nextState.navigation
49
+ * // do something with state changes!
50
50
  * });
51
51
  * ```
52
52
  *
53
53
  * ### Mutating State
54
54
  * ```typescript
55
55
  * NavigationState.update(state => {
56
- * state.currentRoute = "/profile";
57
- * // You can mutate state without creating new objects!
56
+ * state.currentRoute = "/profile";
57
+ * // You can mutate state without creating new objects!
58
58
  * });
59
59
  * ```
60
60
  */
@@ -136,8 +136,8 @@ class Galena {
136
136
  * subscription, call `Galena.unsubscribe()` with the ID returned
137
137
  * by this method
138
138
  */
139
- subscribe(name, mutation) {
140
- return this.get(name).subscribe(mutation);
139
+ subscribe(name, callback) {
140
+ return this.get(name).subscribe(callback);
141
141
  }
142
142
  /**
143
143
  * Unsubscribe
@@ -166,7 +166,7 @@ class Galena {
166
166
  stateSubscriptions.push([
167
167
  key,
168
168
  this.state[key].subscribe(() => {
169
- callback(this);
169
+ callback(this.state);
170
170
  }),
171
171
  ]);
172
172
  }
@@ -50,7 +50,7 @@ import { Scheduler } from "./Scheduler";
50
50
  *
51
51
  * #### Subscribing to State Changes
52
52
  * ```typescript
53
- * MyState.subscribe(({ state }) => {
53
+ * MyState.subscribe((state) => {
54
54
  * const { listItems } = state
55
55
  * // Do something with your list items!
56
56
  * });
@@ -200,7 +200,7 @@ export declare class State<T extends any = any> extends Scheduler {
200
200
  * callback you provide will execute each time state changes.
201
201
  * Returns a unique identifier for your subscription
202
202
  */
203
- subscribe(callback: (nextState: State<T>) => void): string;
203
+ subscribe(callback: (nextState: T) => void): string;
204
204
  /**
205
205
  * Unsubscribe
206
206
  *
@@ -54,7 +54,7 @@ const Scheduler_1 = require("./Scheduler");
54
54
  *
55
55
  * #### Subscribing to State Changes
56
56
  * ```typescript
57
- * MyState.subscribe(({ state }) => {
57
+ * MyState.subscribe((state) => {
58
58
  * const { listItems } = state
59
59
  * // Do something with your list items!
60
60
  * });
@@ -216,7 +216,7 @@ class State extends Scheduler_1.Scheduler {
216
216
  */
217
217
  scheduleUpdate(priority) {
218
218
  this.lifeCycleEvent(types_1.MiddlewareEvents.onUpdate);
219
- void this.scheduleTask(() => this.emitter.emit(this.name, this), priority);
219
+ void this.scheduleTask(() => this.emitter.emit(this.name, this.state), priority);
220
220
  }
221
221
  /**
222
222
  * Register Middleware
@@ -1,6 +1,6 @@
1
1
  import type { State } from "./State";
2
2
  export type MutationEvent<T extends any> = {
3
- [key: State<T>["name"]]: State<T>;
3
+ [key: State<T>["name"]]: T;
4
4
  };
5
5
  export declare enum Priority {
6
6
  "IMMEDIATE" = 1,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@figliolia/galena",
3
- "version": "1.0.1",
3
+ "version": "2.0.1",
4
4
  "description": "A performant state management library supporting mutable state, batched updates, middleware and a rich development API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -34,7 +34,7 @@
34
34
  "lint": "tsc --noemit && eslint ./ --fix"
35
35
  },
36
36
  "dependencies": {
37
- "@figliolia/event-emitter": "^1.0.6"
37
+ "@figliolia/event-emitter": "^1.0.7"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/node": "^16.7.13",
@@ -30,32 +30,32 @@ import { State } from "Galena/State";
30
30
  * import { AppState } from "./AppState";
31
31
  *
32
32
  * AppState.subscribe(appState => {
33
- * const navState = appState.get("navigation");
34
- * const { currentRoute } = navState.state;
35
- * // do something with state changes!
33
+ * const navState = appState.get("navigation");
34
+ * const { currentRoute } = navState.state;
35
+ * // do something with state changes!
36
36
  * });
37
37
  * ```
38
38
  * #### Using the State Instance
39
39
  * ```typescript
40
40
  * NavigationState.subscribe(navigation => {
41
- * const { currentRoute } = navigation.state
42
- * // do something with state changes!
41
+ * const { currentRoute } = navigation
42
+ * // do something with state changes!
43
43
  * });
44
44
  * ```
45
45
  *
46
46
  * #### Using Global Subscriptions
47
47
  * ```typescript
48
- * NavigationState.subscribeAll(galenaInstance => {
49
- * const { currentRoute } = galenaInstance.get("navigation").state
50
- * // do something with state changes!
48
+ * NavigationState.subscribeAll(nextState => {
49
+ * const { currentRoute } = nextState.navigation
50
+ * // do something with state changes!
51
51
  * });
52
52
  * ```
53
53
  *
54
54
  * ### Mutating State
55
55
  * ```typescript
56
56
  * NavigationState.update(state => {
57
- * state.currentRoute = "/profile";
58
- * // You can mutate state without creating new objects!
57
+ * state.currentRoute = "/profile";
58
+ * // You can mutate state without creating new objects!
59
59
  * });
60
60
  * ```
61
61
  */
@@ -166,9 +166,9 @@ export class Galena<
166
166
  */
167
167
  public subscribe<K extends keyof T>(
168
168
  name: K,
169
- mutation: Parameters<T[K]["subscribe"]>["0"]
169
+ callback: Parameters<T[K]["subscribe"]>["0"]
170
170
  ) {
171
- return this.get(name).subscribe(mutation);
171
+ return this.get(name).subscribe(callback);
172
172
  }
173
173
 
174
174
  /**
@@ -192,14 +192,14 @@ export class Galena<
192
192
  * subscription, call `Galena.unsubscribeAll()` with the ID
193
193
  * returned
194
194
  */
195
- public subscribeAll(callback: (state: Galena<T>) => void) {
195
+ public subscribeAll(callback: (nextState: T) => void) {
196
196
  const subscriptionID = this.IDs.get();
197
197
  const stateSubscriptions: [state: string, ID: string][] = [];
198
198
  for (const key in this.state) {
199
199
  stateSubscriptions.push([
200
200
  key,
201
201
  this.state[key].subscribe(() => {
202
- callback(this);
202
+ callback(this.state);
203
203
  }),
204
204
  ]);
205
205
  }
@@ -53,7 +53,7 @@ import { Scheduler } from "./Scheduler";
53
53
  *
54
54
  * #### Subscribing to State Changes
55
55
  * ```typescript
56
- * MyState.subscribe(({ state }) => {
56
+ * MyState.subscribe((state) => {
57
57
  * const { listItems } = state
58
58
  * // Do something with your list items!
59
59
  * });
@@ -237,7 +237,10 @@ export class State<T extends any = any> extends Scheduler {
237
237
  */
238
238
  private scheduleUpdate(priority: Priority) {
239
239
  this.lifeCycleEvent(MiddlewareEvents.onUpdate);
240
- void this.scheduleTask(() => this.emitter.emit(this.name, this), priority);
240
+ void this.scheduleTask(
241
+ () => this.emitter.emit(this.name, this.state),
242
+ priority
243
+ );
241
244
  }
242
245
 
243
246
  /**
@@ -257,7 +260,7 @@ export class State<T extends any = any> extends Scheduler {
257
260
  * callback you provide will execute each time state changes.
258
261
  * Returns a unique identifier for your subscription
259
262
  */
260
- public subscribe(callback: (nextState: State<T>) => void) {
263
+ public subscribe(callback: (nextState: T) => void) {
261
264
  return this.emitter.on(this.name, callback);
262
265
  }
263
266
 
@@ -1,7 +1,7 @@
1
1
  import type { State } from "./State";
2
2
 
3
3
  export type MutationEvent<T extends any> = {
4
- [key: State<T>["name"]]: State<T>;
4
+ [key: State<T>["name"]]: T;
5
5
  };
6
6
 
7
7
  export enum Priority {