@artisan-commerce/state 0.1.0-canary.148.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 ADDED
@@ -0,0 +1 @@
1
+ # State library
@@ -0,0 +1,50 @@
1
+ 'use strict';
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ const _State = class {
20
+ constructor(state) {
21
+ this._state = state;
22
+ this._initialState = state;
23
+ }
24
+ static getInstance(initialState) {
25
+ if (!_State._instance) {
26
+ _State._instance = new _State(initialState);
27
+ }
28
+ return _State._instance;
29
+ }
30
+ setState(overrides) {
31
+ this._state = __spreadValues(__spreadValues({}, this._state), overrides);
32
+ }
33
+ get state() {
34
+ if (this._state === null) {
35
+ throw new Error("The state has not been initialized, make sure to call State.init beforehand");
36
+ }
37
+ return this._state;
38
+ }
39
+ checkInit() {
40
+ return !!this._state;
41
+ }
42
+ reset() {
43
+ this._state = this._initialState;
44
+ }
45
+ };
46
+ let State = _State;
47
+ State._instance = null;
48
+
49
+ exports.State = State;
50
+ //# sourceMappingURL=bundle.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundle.cjs","sources":["../src/lib/state.ts"],"sourcesContent":["// Common functions and data\n\n/**\n * @since 0.1.0\n * @typedef State\n */\nexport type GlobalState = Record<string, any>;\n\n/**\n *\n * Create a global state.\n *\n * @example\n * interface Animal {\n * walk: () => void;\n * name: string;\n * }\n *\n * function getDogState(): State<Animal> {\n * return State.getInstance({ name: \"Rancho\", walk: () => {} });\n * }\n *\n * const dogState = getDogState();\n */\nexport class State<T extends GlobalState> {\n static _instance: State<any> | null = null;\n private _initialState: T;\n private _state: T;\n\n private constructor(state: T) {\n this._state = state;\n this._initialState = state;\n }\n\n public static getInstance<T extends GlobalState>(initialState: T): State<T> {\n if (!State._instance) {\n State._instance = new State<T>(initialState);\n }\n return State._instance as State<T>;\n }\n\n /**\n * Updates the global state.\n *\n * @since 0.1.0\n * @param {T} overrides Global state overrides\n */\n public setState(overrides: Partial<T>) {\n this._state = { ...this._state, ...overrides };\n }\n\n /**\n * Returns the global state.\n *\n * @since 0.1.0\n * @returns {T} The global state\n */\n public get state(): T {\n if (this._state === null) {\n throw new Error(\n \"The state has not been initialized, make sure to call State.init beforehand\"\n );\n }\n return this._state;\n }\n\n /**\n * Returns whether the state has been initialized.\n *\n * @since 0.1.0\n * @returns {boolean} Whether the state has been initialized\n */\n public checkInit(): boolean {\n return !!this._state;\n }\n\n /**\n * Reset state to the given initial state.\n *\n * @since 0.1.0\n */\n public reset() {\n this._state = this._initialState;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAwBO,MAAmC,MAAA,GAAA,MAAA;AAAA,EAKhC,YAAY,KAAU,EAAA;AAC5B,IAAA,IAAA,CAAK,MAAS,GAAA,KAAA;AACd,IAAA,IAAA,CAAK,aAAgB,GAAA,KAAA;AAAA;AAAA,EAAA,OAGT,YAAmC,YAA2B,EAAA;AAC1E,IAAI,IAAA,CAAC,OAAM,SAAW,EAAA;AACpB,MAAM,MAAA,CAAA,SAAA,GAAY,IAAI,MAAS,CAAA,YAAA,CAAA;AAAA;AAEjC,IAAA,OAAO,MAAM,CAAA,SAAA;AAAA;AAAA,EASR,SAAS,SAAuB,EAAA;AACrC,IAAK,IAAA,CAAA,MAAA,GAAS,cAAK,CAAA,cAAA,CAAA,EAAA,EAAA,IAAA,CAAK,MAAW,CAAA,EAAA,SAAA,CAAA;AAAA;AAAA,EAAA,IAS1B,KAAW,GAAA;AACpB,IAAI,IAAA,IAAA,CAAK,WAAW,IAAM,EAAA;AACxB,MAAA,MAAM,IAAI,KACR,CAAA,6EAAA,CAAA;AAAA;AAGJ,IAAA,OAAO,IAAK,CAAA,MAAA;AAAA;AAAA,EASP,SAAqB,GAAA;AAC1B,IAAO,OAAA,CAAC,CAAC,IAAK,CAAA,MAAA;AAAA;AAAA,EAQT,KAAQ,GAAA;AACb,IAAA,IAAA,CAAK,SAAS,IAAK,CAAA,aAAA;AAAA;AAAA,CAAA;AA1DhB,IAAA,KAAA,GAAA;AAAA,MACE,SAA+B,GAAA,IAAA;;;;"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * @since 0.1.0
3
+ * @typedef State
4
+ */
5
+ type GlobalState = Record<string, any>;
6
+ /**
7
+ *
8
+ * Create a global state.
9
+ *
10
+ * @example
11
+ * interface Animal {
12
+ * walk: () => void;
13
+ * name: string;
14
+ * }
15
+ *
16
+ * function getDogState(): State<Animal> {
17
+ * return State.getInstance({ name: "Rancho", walk: () => {} });
18
+ * }
19
+ *
20
+ * const dogState = getDogState();
21
+ */
22
+ declare class State<T extends GlobalState> {
23
+ static _instance: State<any> | null;
24
+ private _initialState;
25
+ private _state;
26
+ private constructor();
27
+ static getInstance<T extends GlobalState>(initialState: T): State<T>;
28
+ /**
29
+ * Updates the global state.
30
+ *
31
+ * @since 0.1.0
32
+ * @param {T} overrides Global state overrides
33
+ */
34
+ setState(overrides: Partial<T>): void;
35
+ /**
36
+ * Returns the global state.
37
+ *
38
+ * @since 0.1.0
39
+ * @returns {T} The global state
40
+ */
41
+ get state(): T;
42
+ /**
43
+ * Returns whether the state has been initialized.
44
+ *
45
+ * @since 0.1.0
46
+ * @returns {boolean} Whether the state has been initialized
47
+ */
48
+ checkInit(): boolean;
49
+ /**
50
+ * Reset state to the given initial state.
51
+ *
52
+ * @since 0.1.0
53
+ */
54
+ reset(): void;
55
+ }
56
+
57
+ export { State };
@@ -0,0 +1,48 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
17
+ const _State = class {
18
+ constructor(state) {
19
+ this._state = state;
20
+ this._initialState = state;
21
+ }
22
+ static getInstance(initialState) {
23
+ if (!_State._instance) {
24
+ _State._instance = new _State(initialState);
25
+ }
26
+ return _State._instance;
27
+ }
28
+ setState(overrides) {
29
+ this._state = __spreadValues(__spreadValues({}, this._state), overrides);
30
+ }
31
+ get state() {
32
+ if (this._state === null) {
33
+ throw new Error("The state has not been initialized, make sure to call State.init beforehand");
34
+ }
35
+ return this._state;
36
+ }
37
+ checkInit() {
38
+ return !!this._state;
39
+ }
40
+ reset() {
41
+ this._state = this._initialState;
42
+ }
43
+ };
44
+ let State = _State;
45
+ State._instance = null;
46
+
47
+ export { State };
48
+ //# sourceMappingURL=bundle.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundle.mjs","sources":["../src/lib/state.ts"],"sourcesContent":["// Common functions and data\n\n/**\n * @since 0.1.0\n * @typedef State\n */\nexport type GlobalState = Record<string, any>;\n\n/**\n *\n * Create a global state.\n *\n * @example\n * interface Animal {\n * walk: () => void;\n * name: string;\n * }\n *\n * function getDogState(): State<Animal> {\n * return State.getInstance({ name: \"Rancho\", walk: () => {} });\n * }\n *\n * const dogState = getDogState();\n */\nexport class State<T extends GlobalState> {\n static _instance: State<any> | null = null;\n private _initialState: T;\n private _state: T;\n\n private constructor(state: T) {\n this._state = state;\n this._initialState = state;\n }\n\n public static getInstance<T extends GlobalState>(initialState: T): State<T> {\n if (!State._instance) {\n State._instance = new State<T>(initialState);\n }\n return State._instance as State<T>;\n }\n\n /**\n * Updates the global state.\n *\n * @since 0.1.0\n * @param {T} overrides Global state overrides\n */\n public setState(overrides: Partial<T>) {\n this._state = { ...this._state, ...overrides };\n }\n\n /**\n * Returns the global state.\n *\n * @since 0.1.0\n * @returns {T} The global state\n */\n public get state(): T {\n if (this._state === null) {\n throw new Error(\n \"The state has not been initialized, make sure to call State.init beforehand\"\n );\n }\n return this._state;\n }\n\n /**\n * Returns whether the state has been initialized.\n *\n * @since 0.1.0\n * @returns {boolean} Whether the state has been initialized\n */\n public checkInit(): boolean {\n return !!this._state;\n }\n\n /**\n * Reset state to the given initial state.\n *\n * @since 0.1.0\n */\n public reset() {\n this._state = this._initialState;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAwBO,MAAmC,MAAA,GAAA,MAAA;AAAA,EAKhC,YAAY,KAAU,EAAA;AAC5B,IAAA,IAAA,CAAK,MAAS,GAAA,KAAA;AACd,IAAA,IAAA,CAAK,aAAgB,GAAA,KAAA;AAAA;AAAA,EAAA,OAGT,YAAmC,YAA2B,EAAA;AAC1E,IAAI,IAAA,CAAC,OAAM,SAAW,EAAA;AACpB,MAAM,MAAA,CAAA,SAAA,GAAY,IAAI,MAAS,CAAA,YAAA,CAAA;AAAA;AAEjC,IAAA,OAAO,MAAM,CAAA,SAAA;AAAA;AAAA,EASR,SAAS,SAAuB,EAAA;AACrC,IAAK,IAAA,CAAA,MAAA,GAAS,cAAK,CAAA,cAAA,CAAA,EAAA,EAAA,IAAA,CAAK,MAAW,CAAA,EAAA,SAAA,CAAA;AAAA;AAAA,EAAA,IAS1B,KAAW,GAAA;AACpB,IAAI,IAAA,IAAA,CAAK,WAAW,IAAM,EAAA;AACxB,MAAA,MAAM,IAAI,KACR,CAAA,6EAAA,CAAA;AAAA;AAGJ,IAAA,OAAO,IAAK,CAAA,MAAA;AAAA;AAAA,EASP,SAAqB,GAAA;AAC1B,IAAO,OAAA,CAAC,CAAC,IAAK,CAAA,MAAA;AAAA;AAAA,EAQT,KAAQ,GAAA;AACb,IAAA,IAAA,CAAK,SAAS,IAAK,CAAA,aAAA;AAAA;AAAA,CAAA;AA1DhB,IAAA,KAAA,GAAA;AAAA,MACE,SAA+B,GAAA,IAAA;;;;"}
@@ -0,0 +1,56 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ArtisnState = {}));
5
+ })(this, (function (exports) { 'use strict';
6
+
7
+ var __defProp = Object.defineProperty;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
+ var __spreadValues = (a, b) => {
13
+ for (var prop in b || (b = {}))
14
+ if (__hasOwnProp.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ if (__getOwnPropSymbols)
17
+ for (var prop of __getOwnPropSymbols(b)) {
18
+ if (__propIsEnum.call(b, prop))
19
+ __defNormalProp(a, prop, b[prop]);
20
+ }
21
+ return a;
22
+ };
23
+ const _State = class {
24
+ constructor(state) {
25
+ this._state = state;
26
+ this._initialState = state;
27
+ }
28
+ static getInstance(initialState) {
29
+ if (!_State._instance) {
30
+ _State._instance = new _State(initialState);
31
+ }
32
+ return _State._instance;
33
+ }
34
+ setState(overrides) {
35
+ this._state = __spreadValues(__spreadValues({}, this._state), overrides);
36
+ }
37
+ get state() {
38
+ if (this._state === null) {
39
+ throw new Error("The state has not been initialized, make sure to call State.init beforehand");
40
+ }
41
+ return this._state;
42
+ }
43
+ checkInit() {
44
+ return !!this._state;
45
+ }
46
+ reset() {
47
+ this._state = this._initialState;
48
+ }
49
+ };
50
+ let State = _State;
51
+ State._instance = null;
52
+
53
+ exports.State = State;
54
+
55
+ }));
56
+ //# sourceMappingURL=bundle.umd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundle.umd.js","sources":["../src/lib/state.ts"],"sourcesContent":["// Common functions and data\n\n/**\n * @since 0.1.0\n * @typedef State\n */\nexport type GlobalState = Record<string, any>;\n\n/**\n *\n * Create a global state.\n *\n * @example\n * interface Animal {\n * walk: () => void;\n * name: string;\n * }\n *\n * function getDogState(): State<Animal> {\n * return State.getInstance({ name: \"Rancho\", walk: () => {} });\n * }\n *\n * const dogState = getDogState();\n */\nexport class State<T extends GlobalState> {\n static _instance: State<any> | null = null;\n private _initialState: T;\n private _state: T;\n\n private constructor(state: T) {\n this._state = state;\n this._initialState = state;\n }\n\n public static getInstance<T extends GlobalState>(initialState: T): State<T> {\n if (!State._instance) {\n State._instance = new State<T>(initialState);\n }\n return State._instance as State<T>;\n }\n\n /**\n * Updates the global state.\n *\n * @since 0.1.0\n * @param {T} overrides Global state overrides\n */\n public setState(overrides: Partial<T>) {\n this._state = { ...this._state, ...overrides };\n }\n\n /**\n * Returns the global state.\n *\n * @since 0.1.0\n * @returns {T} The global state\n */\n public get state(): T {\n if (this._state === null) {\n throw new Error(\n \"The state has not been initialized, make sure to call State.init beforehand\"\n );\n }\n return this._state;\n }\n\n /**\n * Returns whether the state has been initialized.\n *\n * @since 0.1.0\n * @returns {boolean} Whether the state has been initialized\n */\n public checkInit(): boolean {\n return !!this._state;\n }\n\n /**\n * Reset state to the given initial state.\n *\n * @since 0.1.0\n */\n public reset() {\n this._state = this._initialState;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;EAwBO,MAAmC,MAAA,GAAA,MAAA;EAAA,EAKhC,YAAY,KAAU,EAAA;EAC5B,IAAA,IAAA,CAAK,MAAS,GAAA,KAAA;EACd,IAAA,IAAA,CAAK,aAAgB,GAAA,KAAA;EAAA;EAAA,EAAA,OAGT,YAAmC,YAA2B,EAAA;EAC1E,IAAI,IAAA,CAAC,OAAM,SAAW,EAAA;EACpB,MAAM,MAAA,CAAA,SAAA,GAAY,IAAI,MAAS,CAAA,YAAA,CAAA;EAAA;EAEjC,IAAA,OAAO,MAAM,CAAA,SAAA;EAAA;EAAA,EASR,SAAS,SAAuB,EAAA;EACrC,IAAK,IAAA,CAAA,MAAA,GAAS,cAAK,CAAA,cAAA,CAAA,EAAA,EAAA,IAAA,CAAK,MAAW,CAAA,EAAA,SAAA,CAAA;EAAA;EAAA,EAAA,IAS1B,KAAW,GAAA;EACpB,IAAI,IAAA,IAAA,CAAK,WAAW,IAAM,EAAA;EACxB,MAAA,MAAM,IAAI,KACR,CAAA,6EAAA,CAAA;EAAA;EAGJ,IAAA,OAAO,IAAK,CAAA,MAAA;EAAA;EAAA,EASP,SAAqB,GAAA;EAC1B,IAAO,OAAA,CAAC,CAAC,IAAK,CAAA,MAAA;EAAA;EAAA,EAQT,KAAQ,GAAA;EACb,IAAA,IAAA,CAAK,SAAS,IAAK,CAAA,aAAA;EAAA;EAAA,CAAA;AA1DhB,MAAA,KAAA,GAAA;EAAA,MACE,SAA+B,GAAA,IAAA;;;;;;;;"}
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@artisan-commerce/state",
3
+ "description": "Library used to share state functionality",
4
+ "version": "0.1.0-canary.148.1",
5
+ "type": "module",
6
+ "main": "./dist/bundle.cjs",
7
+ "module": "./dist/bundle.mjs",
8
+ "types": "./dist/bundle.d.ts",
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "sideEffects": false,
13
+ "scripts": {
14
+ "compile": "rollup -c && npx agadoo",
15
+ "dev": "yarn compile -w",
16
+ "clean": "rimraf dist",
17
+ "prebuild": "yarn clean",
18
+ "build": "yarn compile",
19
+ "test": "jest --watchAll --runInBand",
20
+ "test:all": "yarn test --watchAll=false --coverage",
21
+ "test:ci": "cross-env CI=true jest --runInBand",
22
+ "test:staged": "yarn test:ci",
23
+ "check-types": "tsc --noEmit",
24
+ "lint": "eslint --ignore-path .gitignore --ignore-pattern !cypress/.eslintrc.cjs --ext .js,jsx,.ts,.tsx .",
25
+ "lint:staged": "yarn lint --max-warnings=0",
26
+ "prettier": "prettier --ignore-path .gitignore \"**/*.+(js|jsx|ts|tsx|json|css|scss|html)\"",
27
+ "format": "yarn prettier --write",
28
+ "check-format": "yarn prettier --list-different",
29
+ "validate": "cross-env CI=true npm-run-all --parallel test:ci check-types check-format lint build",
30
+ "validate:ci": "npm-run-all --parallel check-types check-format lint"
31
+ },
32
+ "author": "Santiago Benítez",
33
+ "license": "MIT",
34
+ "nx": {
35
+ "targets": {
36
+ "build": {
37
+ "outputs": [
38
+ "{projectRoot}/dist"
39
+ ]
40
+ },
41
+ "compile": {
42
+ "outputs": [
43
+ "{projectRoot}/dist"
44
+ ]
45
+ },
46
+ "test:all": {
47
+ "outputs": [
48
+ "{projectRoot}/coverage"
49
+ ]
50
+ }
51
+ }
52
+ },
53
+ "devDependencies": {
54
+ "@artisan-commerce/types": "0.1.0-canary.148.1"
55
+ },
56
+ "gitHead": "6eba4472f02d97014a030d651610de6e3ebcfbed"
57
+ }