@figliolia/galena 2.0.3 → 2.0.5

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.
@@ -17,7 +17,7 @@ export declare class Guards {
17
17
  * developers know that they are attempting to manipulate a
18
18
  * unit of state that has not yet been initialized
19
19
  */
20
- protected warnForUndefinedStates: (name: string, state: Record<string, State<any>>) => void;
20
+ protected warnForUndefinedStates<T extends Record<string, State<any>>>(name: string, state: T): void;
21
21
  /**
22
22
  * Guard Duplicate States
23
23
  *
@@ -25,12 +25,5 @@ export declare class Guards {
25
25
  * more than one state with the same name on a single
26
26
  * `Galena` instance
27
27
  */
28
- protected guardDuplicateStates: (name: string, state: Record<string, State<any>>) => void;
29
- /**
30
- * Development Guard
31
- *
32
- * Wraps a provided function in a check for `process.env.NODE_ENV`
33
- * equaling "development". Returns the callback
34
- */
35
- private developmentGuard;
28
+ protected guardDuplicateStates<T extends Record<string, State<any>>>(name: string, state: T): void;
36
29
  }
@@ -11,45 +11,30 @@ exports.Guards = void 0;
11
11
  * of the library
12
12
  */
13
13
  class Guards {
14
- constructor() {
15
- /**
16
- * Warn For Undefined States
17
- *
18
- * In Galena, it's normal to lazy initialize a unit of state
19
- * in attached to a `Galena` instance. This warning lets
20
- * developers know that they are attempting to manipulate a
21
- * unit of state that has not yet been initialized
22
- */
23
- this.warnForUndefinedStates = this.developmentGuard((name, state) => {
24
- if (!process.env.IGNORE_LAZY_STATE_WARNINGS && !(name in state)) {
25
- console.warn(`A unit of state with the name "${name}" does not yet exist on this Galena instance. If this is expected, you can ignore this warning. To make these warnings go away, you can enable this process argument - "IGNORE_LAZY_STATE_WARNING=1"`);
26
- }
27
- });
28
- /**
29
- * Guard Duplicate States
30
- *
31
- * Throws an error if a developer attempts to create
32
- * more than one state with the same name on a single
33
- * `Galena` instance
34
- */
35
- this.guardDuplicateStates = this.developmentGuard((name, state) => {
36
- if (name in state) {
37
- throw new Error(`A unit of state with the name "${name}" already exists on this Galena instance. Please re-name this new unit of state to something unique`);
38
- }
39
- });
14
+ /**
15
+ * Warn For Undefined States
16
+ *
17
+ * In Galena, it's normal to lazy initialize a unit of state
18
+ * in attached to a `Galena` instance. This warning lets
19
+ * developers know that they are attempting to manipulate a
20
+ * unit of state that has not yet been initialized
21
+ */
22
+ warnForUndefinedStates(name, state) {
23
+ if (!(name in state)) {
24
+ console.warn(`A unit of state with the name "${name}" does not yet exist on this Galena instance. If this is expected, you can ignore this warning`);
25
+ }
40
26
  }
41
27
  /**
42
- * Development Guard
28
+ * Guard Duplicate States
43
29
  *
44
- * Wraps a provided function in a check for `process.env.NODE_ENV`
45
- * equaling "development". Returns the callback
30
+ * Throws an error if a developer attempts to create
31
+ * more than one state with the same name on a single
32
+ * `Galena` instance
46
33
  */
47
- developmentGuard(guard) {
48
- return (...args) => {
49
- if (process.env.NODE_ENV === "development") {
50
- guard(...args);
51
- }
52
- };
34
+ guardDuplicateStates(name, state) {
35
+ if (name in state) {
36
+ console.warn(`A unit of state with the name "${name}" already exists on this Galena instance. Please re-name this new unit of state to something unique`);
37
+ }
53
38
  }
54
39
  }
55
40
  exports.Guards = Guards;
@@ -1,6 +1,4 @@
1
- import { EventEmitter } from "@figliolia/event-emitter";
2
1
  import type { State } from "../Galena/State";
3
- import type { MiddlewareEvent } from "./types";
4
2
  /**
5
3
  * # Middleware
6
4
  *
@@ -30,7 +28,7 @@ import type { MiddlewareEvent } from "./types";
30
28
  * ```
31
29
  */
32
30
  export declare class Middleware<T extends any = any> {
33
- static Emitter: EventEmitter<MiddlewareEvent<any>>;
31
+ private static Emitter;
34
32
  constructor();
35
33
  /**
36
34
  * Validate Event
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@figliolia/galena",
3
- "version": "2.0.3",
3
+ "version": "2.0.5",
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",
@@ -18,18 +18,16 @@ export class Guards {
18
18
  * developers know that they are attempting to manipulate a
19
19
  * unit of state that has not yet been initialized
20
20
  */
21
- protected warnForUndefinedStates = this.developmentGuard(
22
- <T extends Record<string, State<any>>, K extends Extract<keyof T, string>>(
23
- name: K,
24
- state: T
25
- ) => {
26
- if (!process.env.IGNORE_LAZY_STATE_WARNINGS && !(name in state)) {
27
- console.warn(
28
- `A unit of state with the name "${name}" does not yet exist on this Galena instance. If this is expected, you can ignore this warning. To make these warnings go away, you can enable this process argument - "IGNORE_LAZY_STATE_WARNING=1"`
29
- );
30
- }
21
+ protected warnForUndefinedStates<T extends Record<string, State<any>>>(
22
+ name: string,
23
+ state: T
24
+ ) {
25
+ if (!(name in state)) {
26
+ console.warn(
27
+ `A unit of state with the name "${name}" does not yet exist on this Galena instance. If this is expected, you can ignore this warning`
28
+ );
31
29
  }
32
- );
30
+ }
33
31
 
34
32
  /**
35
33
  * Guard Duplicate States
@@ -38,30 +36,14 @@ export class Guards {
38
36
  * more than one state with the same name on a single
39
37
  * `Galena` instance
40
38
  */
41
- protected guardDuplicateStates = this.developmentGuard(
42
- <T extends Record<string, State<any>>, K extends Extract<keyof T, string>>(
43
- name: K,
44
- state: T
45
- ) => {
46
- if (name in state) {
47
- throw new Error(
48
- `A unit of state with the name "${name}" already exists on this Galena instance. Please re-name this new unit of state to something unique`
49
- );
50
- }
39
+ protected guardDuplicateStates<T extends Record<string, State<any>>>(
40
+ name: string,
41
+ state: T
42
+ ) {
43
+ if (name in state) {
44
+ console.warn(
45
+ `A unit of state with the name "${name}" already exists on this Galena instance. Please re-name this new unit of state to something unique`
46
+ );
51
47
  }
52
- );
53
-
54
- /**
55
- * Development Guard
56
- *
57
- * Wraps a provided function in a check for `process.env.NODE_ENV`
58
- * equaling "development". Returns the callback
59
- */
60
- private developmentGuard<F extends (...args: any[]) => void>(guard: F) {
61
- return (...args: Parameters<F>) => {
62
- if (process.env.NODE_ENV === "development") {
63
- guard(...args);
64
- }
65
- };
66
48
  }
67
49
  }
@@ -33,7 +33,7 @@ import { MiddlewareEvents } from "Middleware/types";
33
33
  * ```
34
34
  */
35
35
  export class Middleware<T extends any = any> {
36
- public static Emitter = new EventEmitter<MiddlewareEvent<any>>();
36
+ private static Emitter = new EventEmitter<MiddlewareEvent<any>>();
37
37
  constructor() {
38
38
  const extension = Object.getPrototypeOf(this);
39
39
  const methods = Object.getOwnPropertyNames(extension);