@agile-ts/core
Advanced tools
Comparing version 0.2.0-alpha.1 to 0.2.0-alpha.2
@@ -1,5 +0,8 @@ | ||
import { Runtime, Integrations, SubController, globalBind, Storages, LogCodeManager, defineConfig, } from './internal'; | ||
export class Agile { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Agile = void 0; | ||
const internal_1 = require("./internal"); | ||
class Agile { | ||
constructor(config = {}) { | ||
config = defineConfig(config, { | ||
config = internal_1.defineConfig(config, { | ||
localStorage: false, | ||
@@ -16,14 +19,14 @@ waitForMount: true, | ||
this.key = config.key; | ||
this.integrations = new Integrations(this, { | ||
this.integrations = new internal_1.Integrations(this, { | ||
autoIntegrate: config.autoIntegrate, | ||
}); | ||
this.runtime = new Runtime(this); | ||
this.subController = new SubController(this); | ||
this.storages = new Storages(this, { | ||
this.runtime = new internal_1.Runtime(this); | ||
this.subController = new internal_1.SubController(this); | ||
this.storages = new internal_1.Storages(this, { | ||
localStorage: config.localStorage, | ||
}); | ||
LogCodeManager.log('10:00:00', [], this); | ||
internal_1.LogCodeManager.log('10:00:00', [], this); | ||
if (config.bindGlobal) | ||
if (!globalBind(Agile.globalKey, this)) { | ||
LogCodeManager.log('10:02:00'); | ||
if (!internal_1.globalBind(Agile.globalKey, this)) { | ||
internal_1.LogCodeManager.log('10:02:00'); | ||
} | ||
@@ -46,2 +49,3 @@ } | ||
} | ||
exports.Agile = Agile; | ||
Agile.globalKey = '__agile__'; |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -10,4 +11,6 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
import { defineConfig, LogCodeManager, Persistent, } from '../internal'; | ||
export class CollectionPersistent extends Persistent { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CollectionPersistent = void 0; | ||
const internal_1 = require("../internal"); | ||
class CollectionPersistent extends internal_1.Persistent { | ||
constructor(collection, config = {}) { | ||
@@ -17,3 +20,3 @@ super(collection.agileInstance(), { | ||
}); | ||
config = defineConfig(config, { | ||
config = internal_1.defineConfig(config, { | ||
instantiate: true, | ||
@@ -200,3 +203,3 @@ storageKeys: [], | ||
if (itemKey == null || collectionKey == null) | ||
LogCodeManager.log('1A:02:00'); | ||
internal_1.LogCodeManager.log('1A:02:00'); | ||
if (itemKey == null) | ||
@@ -212,3 +215,3 @@ itemKey = 'unknown'; | ||
if (groupKey == null || collectionKey == null) | ||
LogCodeManager.log('1A:02:01'); | ||
internal_1.LogCodeManager.log('1A:02:01'); | ||
if (groupKey == null) | ||
@@ -223,4 +226,5 @@ groupKey = 'unknown'; | ||
} | ||
exports.CollectionPersistent = CollectionPersistent; | ||
CollectionPersistent.defaultGroupSideEffectKey = 'rebuildGroupStorageValue'; | ||
CollectionPersistent.storageItemKeyPattern = '_${collectionKey}_item_${itemKey}'; | ||
CollectionPersistent.storageGroupKeyPattern = '_${collectionKey}_group_${groupKey}'; |
@@ -1,7 +0,10 @@ | ||
import { Observer, copy, equal, generateId, RuntimeJob, defineConfig, } from '../../internal'; | ||
export class GroupObserver extends Observer { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.GroupObserver = void 0; | ||
const internal_1 = require("../../internal"); | ||
class GroupObserver extends internal_1.Observer { | ||
constructor(group, config = {}) { | ||
super(group.agileInstance(), defineConfig(config, { value: group._output })); | ||
super(group.agileInstance(), internal_1.defineConfig(config, { value: group._output })); | ||
this.group = () => group; | ||
this.nextGroupOutput = copy(group._output); | ||
this.nextGroupOutput = internal_1.copy(group._output); | ||
} | ||
@@ -14,3 +17,3 @@ ingest(config = {}) { | ||
const group = this.group(); | ||
config = defineConfig(config, { | ||
config = internal_1.defineConfig(config, { | ||
perform: true, | ||
@@ -28,12 +31,12 @@ background: false, | ||
} | ||
this.nextGroupOutput = copy(newGroupItems.map((item) => { | ||
this.nextGroupOutput = internal_1.copy(newGroupItems.map((item) => { | ||
return item._value; | ||
})); | ||
if (equal(group._output, this.nextGroupOutput) && !config.force) | ||
if (internal_1.equal(group._output, this.nextGroupOutput) && !config.force) | ||
return; | ||
const job = new RuntimeJob(this, { | ||
const job = new internal_1.RuntimeJob(this, { | ||
sideEffects: config.sideEffects, | ||
force: config.force, | ||
background: config.background, | ||
key: (_a = config.key) !== null && _a !== void 0 ? _a : `${this._key != null ? this._key + '_' : ''}${generateId()}_output`, | ||
key: (_a = config.key) !== null && _a !== void 0 ? _a : `${this._key != null ? this._key + '_' : ''}${internal_1.generateId()}_output`, | ||
maxTriesToUpdate: config.maxTriesToUpdate, | ||
@@ -48,6 +51,7 @@ }); | ||
const group = observer.group(); | ||
group._output = copy(observer.nextGroupOutput); | ||
job.observer.previousValue = copy(job.observer.value); | ||
job.observer.value = copy(group._output); | ||
group._output = internal_1.copy(observer.nextGroupOutput); | ||
job.observer.previousValue = internal_1.copy(job.observer.value); | ||
job.observer.value = internal_1.copy(group._output); | ||
} | ||
} | ||
exports.GroupObserver = GroupObserver; |
@@ -1,3 +0,6 @@ | ||
import { State, normalizeArray, copy, CollectionPersistent, isValidObject, ComputedTracker, removeProperties, LogCodeManager, GroupObserver, StateObserver, defineConfig, } from '../../internal'; | ||
export class Group extends State { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Group = void 0; | ||
const internal_1 = require("../../internal"); | ||
class Group extends internal_1.State { | ||
constructor(collection, initialItems = [], config = {}) { | ||
@@ -8,6 +11,6 @@ super(collection.agileInstance(), initialItems, config); | ||
this.notFoundItemKeys = []; | ||
this.observers['value'] = new StateObserver(this, { | ||
this.observers['value'] = new internal_1.StateObserver(this, { | ||
key: config.key, | ||
}); | ||
this.observers['output'] = new GroupObserver(this, { | ||
this.observers['output'] = new internal_1.GroupObserver(this, { | ||
key: config.key, | ||
@@ -20,7 +23,7 @@ }); | ||
get output() { | ||
ComputedTracker.tracked(this.observers['output']); | ||
return copy(this._output); | ||
internal_1.ComputedTracker.tracked(this.observers['output']); | ||
return internal_1.copy(this._output); | ||
} | ||
set output(value) { | ||
LogCodeManager.log('1C:03:00', [this._key]); | ||
internal_1.LogCodeManager.log('1C:03:00', [this._key]); | ||
} | ||
@@ -34,6 +37,6 @@ has(itemKey) { | ||
remove(itemKeys, config = {}) { | ||
const _itemKeys = normalizeArray(itemKeys); | ||
const _itemKeys = internal_1.normalizeArray(itemKeys); | ||
const notExistingItemKeysInCollection = []; | ||
const notExistingItemKeys = []; | ||
let newGroupValue = copy(this.nextStateValue); | ||
let newGroupValue = internal_1.copy(this.nextStateValue); | ||
_itemKeys.forEach((itemKey) => { | ||
@@ -57,7 +60,7 @@ if (!newGroupValue.includes(itemKey)) { | ||
add(itemKeys, config = {}) { | ||
const _itemKeys = normalizeArray(itemKeys); | ||
const _itemKeys = internal_1.normalizeArray(itemKeys); | ||
const notExistingItemKeysInCollection = []; | ||
const existingItemKeys = []; | ||
let newGroupValue = copy(this.nextStateValue); | ||
defineConfig(config, { | ||
let newGroupValue = internal_1.copy(this.nextStateValue); | ||
internal_1.defineConfig(config, { | ||
method: 'push', | ||
@@ -85,7 +88,7 @@ overwrite: false, | ||
config.background = true; | ||
this.set(newGroupValue, removeProperties(config, ['method', 'overwrite'])); | ||
this.set(newGroupValue, internal_1.removeProperties(config, ['method', 'overwrite'])); | ||
return this; | ||
} | ||
replace(oldItemKey, newItemKey, config = {}) { | ||
const newGroupValue = copy(this._value); | ||
const newGroupValue = internal_1.copy(this._value); | ||
newGroupValue.splice(newGroupValue.indexOf(oldItemKey), 1, newItemKey); | ||
@@ -103,3 +106,3 @@ this.set(newGroupValue, config); | ||
let key; | ||
if (isValidObject(keyOrConfig)) { | ||
if (internal_1.isValidObject(keyOrConfig)) { | ||
_config = keyOrConfig; | ||
@@ -112,3 +115,3 @@ key = this._key; | ||
} | ||
_config = defineConfig(_config, { | ||
_config = internal_1.defineConfig(_config, { | ||
loadValue: true, | ||
@@ -120,3 +123,3 @@ followCollectionPersistKeyPattern: true, | ||
if (_config.followCollectionPersistKeyPattern) { | ||
key = CollectionPersistent.getGroupStorageKey(key || this._key, this.collection()._key); | ||
key = internal_1.CollectionPersistent.getGroupStorageKey(key || this._key, this.collection()._key); | ||
} | ||
@@ -143,3 +146,3 @@ super.persist(key, { | ||
if (notFoundItemKeys.length > 0) { | ||
LogCodeManager.log('1C:02:00', [this.collection()._key, this._key], notFoundItemKeys); | ||
internal_1.LogCodeManager.log('1C:02:00', [this.collection()._key, this._key], notFoundItemKeys); | ||
} | ||
@@ -151,2 +154,3 @@ this.notFoundItemKeys = notFoundItemKeys; | ||
} | ||
exports.Group = Group; | ||
Group.rebuildGroupSideEffectKey = 'rebuildGroup'; |
@@ -570,22 +570,2 @@ import { Agile, Item, Group, GroupKey, Selector, SelectorKey, StorageKey, GroupConfigInterface, CollectionPersistent, GroupAddConfigInterface, SideEffectConfigInterface, SelectorConfigInterface, PatchOptionConfigInterface } from '../internal'; | ||
} | ||
/** | ||
* Returns a newly created Collection. | ||
* | ||
* A Collection manages a reactive set of Information | ||
* that we need to remember globally at a later point in time. | ||
* While providing a toolkit to use and mutate this set of Information. | ||
* | ||
* It is designed for arrays of data objects following the same pattern. | ||
* | ||
* Each of these data object must have a unique `primaryKey` to be correctly identified later. | ||
* | ||
* You can create as many global Collections as you need. | ||
* | ||
* [Learn more..](https://agile-ts.org/docs/core/agile-instance/methods#createcollection) | ||
* | ||
* @public | ||
* @param config - Configuration object | ||
* @param agileInstance - Instance of Agile the Collection belongs to. | ||
*/ | ||
export declare function createCollection<DataType extends Object = DefaultItem>(config?: CollectionConfig<DataType>, agileInstance?: Agile): Collection<DataType>; | ||
export declare type DefaultItem = Record<string, any>; | ||
@@ -592,0 +572,0 @@ export declare type CollectionKey = string | number; |
@@ -1,3 +0,6 @@ | ||
import { Item, Group, Selector, isValidObject, normalizeArray, copy, CollectionPersistent, ComputedTracker, generateId, removeProperties, isFunction, LogCodeManager, defineConfig, shared, } from '../internal'; | ||
export class Collection { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Collection = void 0; | ||
const internal_1 = require("../internal"); | ||
class Collection { | ||
constructor(agileInstance, config = {}) { | ||
@@ -13,3 +16,3 @@ this.size = 0; | ||
let _config = typeof config === 'function' ? config(this) : config; | ||
_config = defineConfig(_config, { | ||
_config = internal_1.defineConfig(_config, { | ||
primaryKey: 'id', | ||
@@ -51,7 +54,7 @@ groups: {}, | ||
if (this.isInstantiated) { | ||
const key = (_a = config.key) !== null && _a !== void 0 ? _a : generateId(); | ||
LogCodeManager.log('1B:02:00'); | ||
const key = (_a = config.key) !== null && _a !== void 0 ? _a : internal_1.generateId(); | ||
internal_1.LogCodeManager.log('1B:02:00'); | ||
return this.createGroup(key, initialItems); | ||
} | ||
return new Group(this, initialItems, config); | ||
return new internal_1.Group(this, initialItems, config); | ||
} | ||
@@ -61,7 +64,7 @@ Selector(initialKey, config = {}) { | ||
if (this.isInstantiated) { | ||
const key = (_a = config.key) !== null && _a !== void 0 ? _a : generateId(); | ||
LogCodeManager.log('1B:02:01'); | ||
const key = (_a = config.key) !== null && _a !== void 0 ? _a : internal_1.generateId(); | ||
internal_1.LogCodeManager.log('1B:02:01'); | ||
return this.createSelector(key, initialKey); | ||
} | ||
return new Selector(this, initialKey, config); | ||
return new internal_1.Selector(this, initialKey, config); | ||
} | ||
@@ -74,3 +77,3 @@ initGroups(groups) { | ||
groups.forEach((groupKey) => { | ||
groupsObject[groupKey] = new Group(this, [], { | ||
groupsObject[groupKey] = new internal_1.Group(this, [], { | ||
key: groupKey, | ||
@@ -82,3 +85,3 @@ }); | ||
groupsObject = groups; | ||
groupsObject[this.config.defaultGroupKey] = new Group(this, [], { | ||
groupsObject[this.config.defaultGroupKey] = new internal_1.Group(this, [], { | ||
key: this.config.defaultGroupKey, | ||
@@ -97,3 +100,3 @@ }); | ||
selectors.forEach((selectorKey) => { | ||
selectorsObject[selectorKey] = new Selector(this, selectorKey, { | ||
selectorsObject[selectorKey] = new internal_1.Selector(this, selectorKey, { | ||
key: selectorKey, | ||
@@ -111,7 +114,7 @@ }); | ||
collect(data, groupKeys, config = {}) { | ||
const _data = normalizeArray(data); | ||
const _groupKeys = normalizeArray(groupKeys); | ||
const _data = internal_1.normalizeArray(data); | ||
const _groupKeys = internal_1.normalizeArray(groupKeys); | ||
const defaultGroupKey = this.config.defaultGroupKey; | ||
const primaryKey = this.config.primaryKey; | ||
config = defineConfig(config, { | ||
config = internal_1.defineConfig(config, { | ||
method: 'push', | ||
@@ -128,3 +131,3 @@ background: false, | ||
let success = false; | ||
if (data instanceof Item) { | ||
if (data instanceof internal_1.Item) { | ||
success = this.assignItem(data, { | ||
@@ -161,3 +164,3 @@ background: config.background, | ||
const primaryKey = this.config.primaryKey; | ||
config = defineConfig(config, { | ||
config = internal_1.defineConfig(config, { | ||
patch: true, | ||
@@ -167,7 +170,7 @@ background: false, | ||
if (item == null) { | ||
LogCodeManager.log('1B:03:00', [itemKey, this._key]); | ||
internal_1.LogCodeManager.log('1B:03:00', [itemKey, this._key]); | ||
return undefined; | ||
} | ||
if (!isValidObject(changes)) { | ||
LogCodeManager.log('1B:03:01', [itemKey, this._key]); | ||
if (!internal_1.isValidObject(changes)) { | ||
internal_1.LogCodeManager.log('1B:03:01', [itemKey, this._key]); | ||
return undefined; | ||
@@ -194,3 +197,3 @@ } | ||
changes[this.config.primaryKey] = itemKey; | ||
LogCodeManager.log('1B:02:02', [], changes); | ||
internal_1.LogCodeManager.log('1B:02:02', [], changes); | ||
} | ||
@@ -206,6 +209,6 @@ item.set(changes, { | ||
if (!this.isInstantiated) | ||
LogCodeManager.log('1B:02:03'); | ||
internal_1.LogCodeManager.log('1B:02:03'); | ||
if (group != null) { | ||
if (!group.isPlaceholder) { | ||
LogCodeManager.log('1B:03:02', [groupKey]); | ||
internal_1.LogCodeManager.log('1B:03:02', [groupKey]); | ||
return group; | ||
@@ -216,3 +219,3 @@ } | ||
} | ||
group = new Group(this, initialItems, { key: groupKey }); | ||
group = new internal_1.Group(this, initialItems, { key: groupKey }); | ||
this.groups[groupKey] = group; | ||
@@ -225,3 +228,3 @@ return group; | ||
getGroup(groupKey, config = {}) { | ||
config = defineConfig(config, { | ||
config = internal_1.defineConfig(config, { | ||
notExisting: false, | ||
@@ -232,3 +235,3 @@ }); | ||
return undefined; | ||
ComputedTracker.tracked(group.observers['value']); | ||
internal_1.ComputedTracker.tracked(group.observers['value']); | ||
return group; | ||
@@ -242,3 +245,3 @@ } | ||
if (group == null) { | ||
group = new Group(this, [], { | ||
group = new internal_1.Group(this, [], { | ||
key: groupKey, | ||
@@ -249,3 +252,3 @@ isPlaceholder: true, | ||
} | ||
ComputedTracker.tracked(group.observers['value']); | ||
internal_1.ComputedTracker.tracked(group.observers['value']); | ||
return group; | ||
@@ -266,6 +269,6 @@ } | ||
if (!this.isInstantiated) | ||
LogCodeManager.log('1B:02:04'); | ||
internal_1.LogCodeManager.log('1B:02:04'); | ||
if (selector != null) { | ||
if (!selector.isPlaceholder) { | ||
LogCodeManager.log('1B:03:03', [selectorKey]); | ||
internal_1.LogCodeManager.log('1B:03:03', [selectorKey]); | ||
return selector; | ||
@@ -276,3 +279,3 @@ } | ||
} | ||
selector = new Selector(this, itemKey, { | ||
selector = new internal_1.Selector(this, itemKey, { | ||
key: selectorKey, | ||
@@ -290,3 +293,3 @@ }); | ||
getSelector(selectorKey, config = {}) { | ||
config = defineConfig(config, { | ||
config = internal_1.defineConfig(config, { | ||
notExisting: false, | ||
@@ -297,3 +300,3 @@ }); | ||
return undefined; | ||
ComputedTracker.tracked(selector.observers['value']); | ||
internal_1.ComputedTracker.tracked(selector.observers['value']); | ||
return selector; | ||
@@ -304,3 +307,3 @@ } | ||
if (selector == null) { | ||
selector = new Selector(this, null, { | ||
selector = new internal_1.Selector(this, null, { | ||
key: selectorKey, | ||
@@ -311,3 +314,3 @@ isPlaceholder: true, | ||
} | ||
ComputedTracker.tracked(selector.observers['value']); | ||
internal_1.ComputedTracker.tracked(selector.observers['value']); | ||
return selector; | ||
@@ -331,3 +334,3 @@ } | ||
getItem(itemKey, config = {}) { | ||
config = defineConfig(config, { | ||
config = internal_1.defineConfig(config, { | ||
notExisting: false, | ||
@@ -338,3 +341,3 @@ }); | ||
return undefined; | ||
ComputedTracker.tracked(item.observers['value']); | ||
internal_1.ComputedTracker.tracked(item.observers['value']); | ||
return item; | ||
@@ -346,7 +349,7 @@ } | ||
item = this.createPlaceholderItem(itemKey, true); | ||
ComputedTracker.tracked(item.observers['value']); | ||
internal_1.ComputedTracker.tracked(item.observers['value']); | ||
return item; | ||
} | ||
createPlaceholderItem(itemKey, addToCollection = false) { | ||
const item = new Item(this, { | ||
const item = new internal_1.Item(this, { | ||
[this.config.primaryKey]: itemKey, | ||
@@ -358,3 +361,3 @@ dummy: 'item', | ||
this.data[itemKey] = item; | ||
ComputedTracker.tracked(item.observers['value']); | ||
internal_1.ComputedTracker.tracked(item.observers['value']); | ||
return item; | ||
@@ -369,3 +372,3 @@ } | ||
getAllItems(config = {}) { | ||
config = defineConfig(config, { | ||
config = internal_1.defineConfig(config, { | ||
notExisting: false, | ||
@@ -391,3 +394,3 @@ }); | ||
let key; | ||
if (isValidObject(keyOrConfig)) { | ||
if (internal_1.isValidObject(keyOrConfig)) { | ||
_config = keyOrConfig; | ||
@@ -400,3 +403,3 @@ key = this._key; | ||
} | ||
_config = defineConfig(_config, { | ||
_config = internal_1.defineConfig(_config, { | ||
loadValue: true, | ||
@@ -408,3 +411,3 @@ storageKeys: [], | ||
return this; | ||
this.persistent = new CollectionPersistent(this, { | ||
this.persistent = new internal_1.CollectionPersistent(this, { | ||
instantiate: _config.loadValue, | ||
@@ -420,4 +423,4 @@ storageKeys: _config.storageKeys, | ||
return this; | ||
if (!isFunction(callback)) { | ||
LogCodeManager.log('00:03:01', ['OnLoad Callback', 'function']); | ||
if (!internal_1.isFunction(callback)) { | ||
internal_1.LogCodeManager.log('00:03:01', ['OnLoad Callback', 'function']); | ||
return this; | ||
@@ -441,4 +444,4 @@ } | ||
put(itemKeys, groupKeys, config = {}) { | ||
const _itemKeys = normalizeArray(itemKeys); | ||
const _groupKeys = normalizeArray(groupKeys); | ||
const _itemKeys = internal_1.normalizeArray(itemKeys); | ||
const _groupKeys = internal_1.normalizeArray(groupKeys); | ||
_groupKeys.forEach((groupKey) => { | ||
@@ -452,4 +455,4 @@ var _a; | ||
var _a, _b; | ||
const _itemKeys = normalizeArray(itemKeys); | ||
(_a = this.getGroup(oldGroupKey)) === null || _a === void 0 ? void 0 : _a.remove(_itemKeys, removeProperties(config, ['method', 'overwrite'])); | ||
const _itemKeys = internal_1.normalizeArray(itemKeys); | ||
(_a = this.getGroup(oldGroupKey)) === null || _a === void 0 ? void 0 : _a.remove(_itemKeys, internal_1.removeProperties(config, ['method', 'overwrite'])); | ||
(_b = this.getGroup(newGroupKey)) === null || _b === void 0 ? void 0 : _b.add(_itemKeys, config); | ||
@@ -461,3 +464,3 @@ return this; | ||
const item = this.getItem(oldItemKey, { notExisting: true }); | ||
config = defineConfig(config, { | ||
config = internal_1.defineConfig(config, { | ||
background: false, | ||
@@ -468,3 +471,3 @@ }); | ||
if (this.hasItem(newItemKey)) { | ||
LogCodeManager.log('1B:03:04', [oldItemKey, newItemKey, this._key]); | ||
internal_1.LogCodeManager.log('1B:03:04', [oldItemKey, newItemKey, this._key]); | ||
return false; | ||
@@ -479,4 +482,4 @@ } | ||
item.persistent._key === | ||
CollectionPersistent.getItemStorageKey(oldItemKey, this._key)) | ||
(_a = item.persistent) === null || _a === void 0 ? void 0 : _a.setKey(CollectionPersistent.getItemStorageKey(newItemKey, this._key)); | ||
internal_1.CollectionPersistent.getItemStorageKey(oldItemKey, this._key)) | ||
(_a = item.persistent) === null || _a === void 0 ? void 0 : _a.setKey(internal_1.CollectionPersistent.getItemStorageKey(newItemKey, this._key)); | ||
for (const groupKey in this.groups) { | ||
@@ -521,4 +524,4 @@ const group = this.getGroup(groupKey, { notExisting: true }); | ||
removeFromGroups(itemKeys, groupKeys) { | ||
const _itemKeys = normalizeArray(itemKeys); | ||
const _groupKeys = normalizeArray(groupKeys); | ||
const _itemKeys = internal_1.normalizeArray(itemKeys); | ||
const _groupKeys = internal_1.normalizeArray(groupKeys); | ||
_itemKeys.forEach((itemKey) => { | ||
@@ -540,7 +543,7 @@ let removedFromGroupsCount = 0; | ||
removeItems(itemKeys, config = {}) { | ||
config = defineConfig(config, { | ||
config = internal_1.defineConfig(config, { | ||
notExisting: false, | ||
removeSelector: false, | ||
}); | ||
const _itemKeys = normalizeArray(itemKeys); | ||
const _itemKeys = internal_1.normalizeArray(itemKeys); | ||
_itemKeys.forEach((itemKey) => { | ||
@@ -576,15 +579,15 @@ var _a, _b; | ||
assignData(data, config = {}) { | ||
config = defineConfig(config, { | ||
config = internal_1.defineConfig(config, { | ||
patch: false, | ||
background: false, | ||
}); | ||
const _data = copy(data); | ||
const _data = internal_1.copy(data); | ||
const primaryKey = this.config.primaryKey; | ||
if (!isValidObject(_data)) { | ||
LogCodeManager.log('1B:03:05', [this._key]); | ||
if (!internal_1.isValidObject(_data)) { | ||
internal_1.LogCodeManager.log('1B:03:05', [this._key]); | ||
return false; | ||
} | ||
if (!Object.prototype.hasOwnProperty.call(_data, primaryKey)) { | ||
LogCodeManager.log('1B:02:05', [this._key, primaryKey]); | ||
_data[primaryKey] = generateId(); | ||
internal_1.LogCodeManager.log('1B:02:05', [this._key, primaryKey]); | ||
_data[primaryKey] = internal_1.generateId(); | ||
} | ||
@@ -603,3 +606,3 @@ const itemKey = _data[primaryKey]; | ||
else { | ||
this.assignItem(new Item(this, _data), { | ||
this.assignItem(new internal_1.Item(this, _data), { | ||
background: config.background, | ||
@@ -613,3 +616,3 @@ }); | ||
assignItem(item, config = {}) { | ||
config = defineConfig(config, { | ||
config = internal_1.defineConfig(config, { | ||
overwrite: false, | ||
@@ -622,4 +625,4 @@ background: false, | ||
if (!Object.prototype.hasOwnProperty.call(item._value, primaryKey)) { | ||
LogCodeManager.log('1B:02:05', [this._key, primaryKey]); | ||
itemKey = generateId(); | ||
internal_1.LogCodeManager.log('1B:02:05', [this._key, primaryKey]); | ||
itemKey = internal_1.generateId(); | ||
item.patch({ [this.config.primaryKey]: itemKey }, { background: config.background }); | ||
@@ -629,3 +632,3 @@ item._key = itemKey; | ||
if (item.collection() !== this) { | ||
LogCodeManager.log('1B:03:06', [this._key, item.collection()._key]); | ||
internal_1.LogCodeManager.log('1B:03:06', [this._key, item.collection()._key]); | ||
return false; | ||
@@ -650,3 +653,3 @@ } | ||
rebuildGroupsThatIncludeItemKey(itemKey, config = {}) { | ||
config = defineConfig(config, { | ||
config = internal_1.defineConfig(config, { | ||
background: false, | ||
@@ -670,4 +673,2 @@ sideEffects: { | ||
} | ||
export function createCollection(config, agileInstance = shared) { | ||
return new Collection(agileInstance, config); | ||
} | ||
exports.Collection = Collection; |
@@ -1,3 +0,6 @@ | ||
import { State, isValidObject, CollectionPersistent, defineConfig, } from '../internal'; | ||
export class Item extends State { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Item = void 0; | ||
const internal_1 = require("../internal"); | ||
class Item extends internal_1.State { | ||
constructor(collection, data, config = {}) { | ||
@@ -16,3 +19,3 @@ super(collection.agileInstance(), data, { | ||
super.setKey(value); | ||
config = defineConfig(config, { | ||
config = internal_1.defineConfig(config, { | ||
sideEffects: { | ||
@@ -37,3 +40,3 @@ enabled: true, | ||
let key; | ||
if (isValidObject(keyOrConfig)) { | ||
if (internal_1.isValidObject(keyOrConfig)) { | ||
_config = keyOrConfig; | ||
@@ -46,3 +49,3 @@ key = this._key; | ||
} | ||
_config = defineConfig(_config, { | ||
_config = internal_1.defineConfig(_config, { | ||
loadValue: true, | ||
@@ -54,3 +57,3 @@ followCollectionPersistKeyPattern: true, | ||
if (_config.followCollectionPersistKeyPattern) { | ||
key = CollectionPersistent.getItemStorageKey(key || this._key, this.collection()._key); | ||
key = internal_1.CollectionPersistent.getItemStorageKey(key || this._key, this.collection()._key); | ||
} | ||
@@ -70,2 +73,3 @@ super.persist(key, { | ||
} | ||
exports.Item = Item; | ||
Item.updateGroupSideEffectKey = 'rebuildGroup'; |
@@ -1,5 +0,8 @@ | ||
import { defineConfig, State, } from '../internal'; | ||
export class Selector extends State { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Selector = void 0; | ||
const internal_1 = require("../internal"); | ||
class Selector extends internal_1.State { | ||
constructor(collection, itemKey, config = {}) { | ||
config = defineConfig(config, { | ||
config = internal_1.defineConfig(config, { | ||
isPlaceholder: false, | ||
@@ -31,3 +34,3 @@ }); | ||
var _a, _b; | ||
config = defineConfig(config, { | ||
config = internal_1.defineConfig(config, { | ||
background: false, | ||
@@ -106,3 +109,4 @@ sideEffects: { | ||
} | ||
exports.Selector = Selector; | ||
Selector.rebuildSelectorSideEffectKey = 'rebuildSelector'; | ||
Selector.rebuildItemSideEffectKey = 'rebuildItem'; |
@@ -1,2 +0,5 @@ | ||
export class ComputedTracker { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ComputedTracker = void 0; | ||
class ComputedTracker { | ||
constructor() { | ||
@@ -18,3 +21,4 @@ } | ||
} | ||
exports.ComputedTracker = ComputedTracker; | ||
ComputedTracker.isTracking = false; | ||
ComputedTracker.trackedObservers = new Set(); |
@@ -1,2 +0,2 @@ | ||
import { State, Agile, Observer, StateConfigInterface, Collection, StateIngestConfigInterface, CreateAgileSubInstanceInterface } from '../internal'; | ||
import { State, Agile, Observer, StateConfigInterface, Collection, StateIngestConfigInterface } from '../internal'; | ||
export declare class Computed<ComputedValueType = any> extends State<ComputedValueType> { | ||
@@ -7,2 +7,3 @@ config: ComputedConfigInterface; | ||
hardCodedDeps: Array<Observer>; | ||
isComputed: boolean; | ||
/** | ||
@@ -65,42 +66,2 @@ * A Computed is an extension of the State Class | ||
} | ||
/** | ||
* Returns a newly created Computed. | ||
* | ||
* A Computed is an extension of the State Class | ||
* that computes its value based on a specified compute function. | ||
* | ||
* The computed value will be cached to avoid unnecessary recomputes | ||
* and is only recomputed when one of its direct dependencies changes. | ||
* | ||
* Direct dependencies can be States and Collections. | ||
* So when, for example, a dependent State value changes, the computed value is recomputed. | ||
* | ||
* [Learn more..](https://agile-ts.org/docs/core/agile-instance/methods#createstate) | ||
* | ||
* @public | ||
* @param computeFunction - Function to compute the computed value. | ||
* @param config - Configuration object | ||
*/ | ||
export declare function createComputed<ComputedValueType = any>(computeFunction: ComputeFunctionType<ComputedValueType>, config?: CreateComputedConfigInterfaceWithAgile): Computed<ComputedValueType>; | ||
/** | ||
* Returns a newly created Computed. | ||
* | ||
* A Computed is an extension of the State Class | ||
* that computes its value based on a specified compute function. | ||
* | ||
* The computed value will be cached to avoid unnecessary recomputes | ||
* and is only recomputed when one of its direct dependencies changes. | ||
* | ||
* Direct dependencies can be States and Collections. | ||
* So when, for example, a dependent State value changes, the computed value is recomputed. | ||
* | ||
* [Learn more..](https://agile-ts.org/docs/core/agile-instance/methods#createcomputed) | ||
* | ||
* @public | ||
* @param computeFunction - Function to compute the computed value. | ||
* @param deps - Hard-coded dependencies on which the Computed Class should depend. | ||
*/ | ||
export declare function createComputed<ComputedValueType = any>(computeFunction: ComputeFunctionType<ComputedValueType>, deps?: Array<DependableAgileInstancesType>): Computed<ComputedValueType>; | ||
export interface CreateComputedConfigInterfaceWithAgile extends CreateAgileSubInstanceInterface, CreateComputedConfigInterface { | ||
} | ||
export declare type ComputeFunctionType<ComputedValueType = any> = () => ComputedValueType | Promise<ComputedValueType>; | ||
@@ -107,0 +68,0 @@ export interface CreateComputedConfigInterface extends StateConfigInterface { |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -10,4 +11,6 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
import { State, ComputedTracker, removeProperties, LogCodeManager, isAsyncFunction, extractRelevantObservers, defineConfig, shared, } from '../internal'; | ||
export class Computed extends State { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Computed = void 0; | ||
const internal_1 = require("../internal"); | ||
class Computed extends internal_1.State { | ||
constructor(agileInstance, computeFunction, config = {}) { | ||
@@ -20,5 +23,6 @@ super(agileInstance, null, { | ||
this.hardCodedDeps = []; | ||
config = defineConfig(config, { | ||
this.isComputed = true; | ||
config = internal_1.defineConfig(config, { | ||
computedDeps: [], | ||
autodetect: !isAsyncFunction(computeFunction), | ||
autodetect: !internal_1.isAsyncFunction(computeFunction), | ||
}); | ||
@@ -30,3 +34,3 @@ this.agileInstance = () => agileInstance; | ||
}; | ||
this.hardCodedDeps = extractRelevantObservers(config.computedDeps).filter((dep) => dep !== undefined); | ||
this.hardCodedDeps = internal_1.extractRelevantObservers(config.computedDeps).filter((dep) => dep !== undefined); | ||
this.deps = new Set(this.hardCodedDeps); | ||
@@ -39,7 +43,7 @@ this.deps.forEach((observer) => { | ||
recompute(config = {}) { | ||
config = defineConfig(config, { | ||
config = internal_1.defineConfig(config, { | ||
autodetect: false, | ||
}); | ||
this.compute({ autodetect: config.autodetect }).then((result) => { | ||
this.observers['value'].ingestValue(result, removeProperties(config, ['autodetect'])); | ||
this.observers['value'].ingestValue(result, internal_1.removeProperties(config, ['autodetect'])); | ||
}); | ||
@@ -49,3 +53,3 @@ return this; | ||
updateComputeFunction(computeFunction, deps = [], config = {}) { | ||
config = defineConfig(config, { | ||
config = internal_1.defineConfig(config, { | ||
autodetect: this.config.autodetect, | ||
@@ -56,3 +60,3 @@ }); | ||
}); | ||
this.hardCodedDeps = extractRelevantObservers(deps).filter((dep) => dep !== undefined); | ||
this.hardCodedDeps = internal_1.extractRelevantObservers(deps).filter((dep) => dep !== undefined); | ||
this.deps = new Set(this.hardCodedDeps); | ||
@@ -63,3 +67,3 @@ this.deps.forEach((observer) => { | ||
this.computeFunction = computeFunction; | ||
this.recompute(removeProperties(config, ['overwriteDeps'])); | ||
this.recompute(internal_1.removeProperties(config, ['overwriteDeps'])); | ||
return this; | ||
@@ -69,10 +73,10 @@ } | ||
return __awaiter(this, void 0, void 0, function* () { | ||
config = defineConfig(config, { | ||
config = internal_1.defineConfig(config, { | ||
autodetect: this.config.autodetect, | ||
}); | ||
if (config.autodetect) | ||
ComputedTracker.track(); | ||
internal_1.ComputedTracker.track(); | ||
const computedValue = this.computeFunction(); | ||
if (config.autodetect) { | ||
const foundDeps = ComputedTracker.getTrackedObservers(); | ||
const foundDeps = internal_1.ComputedTracker.getTrackedObservers(); | ||
this.deps.forEach((observer) => { | ||
@@ -96,19 +100,6 @@ if (!foundDeps.includes(observer) && | ||
persist() { | ||
LogCodeManager.log('19:03:00'); | ||
internal_1.LogCodeManager.log('19:03:00'); | ||
return this; | ||
} | ||
} | ||
export function createComputed(computeFunction, configOrDeps) { | ||
let _config = {}; | ||
if (Array.isArray(configOrDeps)) { | ||
_config = defineConfig(_config, { | ||
computedDeps: configOrDeps, | ||
}); | ||
} | ||
else { | ||
if (configOrDeps) | ||
_config = configOrDeps; | ||
} | ||
_config = defineConfig(_config, { agileInstance: shared }); | ||
return new Computed(_config.agileInstance, computeFunction, removeProperties(_config, ['agileInstance'])); | ||
} | ||
exports.Computed = Computed; |
@@ -1,3 +0,15 @@ | ||
import { Agile } from './internal'; | ||
export * from './internal'; | ||
export default Agile; | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const internal_1 = require("./internal"); | ||
__exportStar(require("./internal"), exports); | ||
exports.default = internal_1.Agile; |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -10,8 +11,10 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
import { Integration, LogCodeManager, defineConfig } from '../internal'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Integrations = void 0; | ||
const internal_1 = require("../internal"); | ||
const onRegisterInitialIntegrationCallbacks = []; | ||
export class Integrations { | ||
class Integrations { | ||
constructor(agileInstance, config = {}) { | ||
this.integrations = new Set(); | ||
config = defineConfig(config, { | ||
config = internal_1.defineConfig(config, { | ||
autoIntegrate: true, | ||
@@ -27,3 +30,3 @@ }); | ||
static addInitialIntegration(integration) { | ||
if (integration instanceof Integration) { | ||
if (integration instanceof internal_1.Integration) { | ||
onRegisterInitialIntegrationCallbacks.forEach((callback) => callback(integration)); | ||
@@ -42,3 +45,3 @@ Integrations.initialIntegrations.push(integration); | ||
if (integration._key == null) { | ||
LogCodeManager.log('18:03:00', [integration._key, this.agileInstance().key], integration); | ||
internal_1.LogCodeManager.log('18:03:00', [integration._key, this.agileInstance().key], integration); | ||
return false; | ||
@@ -52,3 +55,3 @@ } | ||
integration.integrated = true; | ||
LogCodeManager.log('18:00:00', [integration._key, this.agileInstance().key], integration); | ||
internal_1.LogCodeManager.log('18:00:00', [integration._key, this.agileInstance().key], integration); | ||
return true; | ||
@@ -60,3 +63,3 @@ }); | ||
if (!integration.ready) { | ||
LogCodeManager.log('18:02:00', [integration._key]); | ||
internal_1.LogCodeManager.log('18:02:00', [integration._key]); | ||
return; | ||
@@ -72,2 +75,3 @@ } | ||
} | ||
exports.Integrations = Integrations; | ||
Integrations.initialIntegrations = []; |
@@ -1,2 +0,5 @@ | ||
export class Integration { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Integration = void 0; | ||
class Integration { | ||
constructor(config) { | ||
@@ -19,1 +22,2 @@ this.ready = false; | ||
} | ||
exports.Integration = Integration; |
@@ -1,29 +0,41 @@ | ||
export * from './utils'; | ||
export * from '@agile-ts/utils'; | ||
export * from './logCodeManager'; | ||
export * from './agile'; | ||
export * from './integrations'; | ||
export * from './integrations/integration'; | ||
export * from './runtime'; | ||
export * from './runtime/observer'; | ||
export * from './runtime/runtime.job'; | ||
export * from './runtime/subscription/container/SubscriptionContainer'; | ||
export * from './runtime/subscription/container/CallbackSubscriptionContainer'; | ||
export * from './runtime/subscription/container/ComponentSubscriptionContainer'; | ||
export * from './runtime/subscription/sub.controller'; | ||
export * from './storages'; | ||
export * from './storages/storage'; | ||
export * from './storages/persistent'; | ||
export * from './state'; | ||
export * from './state/state.observer'; | ||
export * from './state/state.persistent'; | ||
export * from './state/state.runtime.job'; | ||
export * from './computed'; | ||
export * from './computed/computed.tracker'; | ||
export * from './collection'; | ||
export * from './collection/group'; | ||
export * from './collection/group/group.observer'; | ||
export * from './collection/item'; | ||
export * from './collection/selector'; | ||
export * from './collection/collection.persistent'; | ||
export * from './shared'; | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./utils"), exports); | ||
__exportStar(require("@agile-ts/utils"), exports); | ||
__exportStar(require("./logCodeManager"), exports); | ||
__exportStar(require("./agile"), exports); | ||
__exportStar(require("./integrations"), exports); | ||
__exportStar(require("./integrations/integration"), exports); | ||
__exportStar(require("./runtime"), exports); | ||
__exportStar(require("./runtime/observer"), exports); | ||
__exportStar(require("./runtime/runtime.job"), exports); | ||
__exportStar(require("./runtime/subscription/container/SubscriptionContainer"), exports); | ||
__exportStar(require("./runtime/subscription/container/CallbackSubscriptionContainer"), exports); | ||
__exportStar(require("./runtime/subscription/container/ComponentSubscriptionContainer"), exports); | ||
__exportStar(require("./runtime/subscription/sub.controller"), exports); | ||
__exportStar(require("./storages"), exports); | ||
__exportStar(require("./storages/storage"), exports); | ||
__exportStar(require("./storages/persistent"), exports); | ||
__exportStar(require("./state"), exports); | ||
__exportStar(require("./state/state.observer"), exports); | ||
__exportStar(require("./state/state.persistent"), exports); | ||
__exportStar(require("./state/state.runtime.job"), exports); | ||
__exportStar(require("./computed"), exports); | ||
__exportStar(require("./computed/computed.tracker"), exports); | ||
__exportStar(require("./collection"), exports); | ||
__exportStar(require("./collection/group"), exports); | ||
__exportStar(require("./collection/group/group.observer"), exports); | ||
__exportStar(require("./collection/item"), exports); | ||
__exportStar(require("./collection/selector"), exports); | ||
__exportStar(require("./collection/collection.persistent"), exports); | ||
__exportStar(require("./shared"), exports); |
@@ -22,4 +22,2 @@ export declare let loggerPackage: any; | ||
'13:03:00': string; | ||
'14:02:00': string; | ||
'14:03:00': string; | ||
'14:03:01': string; | ||
@@ -134,4 +132,2 @@ '14:03:02': string; | ||
'13:03:00': string; | ||
'14:02:00': string; | ||
'14:03:00': string; | ||
'14:03:01': string; | ||
@@ -138,0 +134,0 @@ '14:03:02': string; |
@@ -1,4 +0,7 @@ | ||
export let loggerPackage = null; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.LogCodeManager = exports.loggerPackage = void 0; | ||
exports.loggerPackage = null; | ||
try { | ||
loggerPackage = require('@agile-ts/logger'); | ||
exports.loggerPackage = require('@agile-ts/logger'); | ||
} | ||
@@ -37,4 +40,2 @@ catch (e) { | ||
'13:03:00': "Invalid Storage '${0}()' method provided!", | ||
'14:02:00': "Incorrect type '${0}' was provided! Requires type of ${1}.", | ||
'14:03:00': "Incorrect type '${0}' was provided! Requires type of ${1}.", | ||
'14:03:01': "'${1}' is a not supported type! Supported types are: String, Boolean, Array, Object, Number.", | ||
@@ -105,3 +106,3 @@ '14:03:02': "The 'patch()' method works only in object based States!", | ||
function log(logCode, replacers = [], ...data) { | ||
const logger = LogCodeManager.getLogger(); | ||
const logger = exports.LogCodeManager.getLogger(); | ||
if (logger != null && !logger.isActive) | ||
@@ -120,3 +121,3 @@ return; | ||
function logIfTags(tags, logCode, replacers = [], ...data) { | ||
const logger = LogCodeManager.getLogger(); | ||
const logger = exports.LogCodeManager.getLogger(); | ||
if (logger != null && !logger.isActive) | ||
@@ -132,3 +133,3 @@ return; | ||
} | ||
export const LogCodeManager = { | ||
exports.LogCodeManager = { | ||
getLog, | ||
@@ -140,5 +141,5 @@ log, | ||
var _a; | ||
return (_a = loggerPackage === null || loggerPackage === void 0 ? void 0 : loggerPackage.sharedAgileLogger) !== null && _a !== void 0 ? _a : null; | ||
return (_a = exports.loggerPackage === null || exports.loggerPackage === void 0 ? void 0 : exports.loggerPackage.sharedAgileLogger) !== null && _a !== void 0 ? _a : null; | ||
}, | ||
logIfTags, | ||
}; |
@@ -1,3 +0,6 @@ | ||
import { CallbackSubscriptionContainer, ComponentSubscriptionContainer, notEqual, LogCodeManager, defineConfig, } from '../internal'; | ||
export class Runtime { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Runtime = void 0; | ||
const internal_1 = require("../internal"); | ||
class Runtime { | ||
constructor(agileInstance) { | ||
@@ -13,7 +16,7 @@ this.currentJob = null; | ||
ingest(job, config = {}) { | ||
config = defineConfig(config, { | ||
config = internal_1.defineConfig(config, { | ||
perform: !this.isPerformingJobs, | ||
}); | ||
this.jobQueue.push(job); | ||
LogCodeManager.logIfTags(['runtime'], '16:01:00', [job._key], job); | ||
internal_1.LogCodeManager.logIfTags(['runtime'], '16:01:00', [job._key], job); | ||
if (config.perform) { | ||
@@ -34,3 +37,3 @@ const performJob = this.jobQueue.shift(); | ||
this.currentJob = null; | ||
LogCodeManager.logIfTags(['runtime'], '16:01:01', [job._key], job); | ||
internal_1.LogCodeManager.logIfTags(['runtime'], '16:01:01', [job._key], job); | ||
if (this.jobQueue.length > 0) { | ||
@@ -80,6 +83,6 @@ const performJob = this.jobQueue.shift(); | ||
this.notReadyJobsToRerender.add(job); | ||
LogCodeManager.log('16:02:00', [subscriptionContainer.key], subscriptionContainer); | ||
internal_1.LogCodeManager.log('16:02:00', [subscriptionContainer.key], subscriptionContainer); | ||
} | ||
else { | ||
LogCodeManager.log('16:02:01', [job.config.maxTriesToUpdate], subscriptionContainer); | ||
internal_1.LogCodeManager.log('16:02:01', [job.config.maxTriesToUpdate], subscriptionContainer); | ||
} | ||
@@ -103,9 +106,9 @@ return; | ||
const subscriptionContainer = subscriptionsToUpdate[i]; | ||
if (subscriptionContainer instanceof CallbackSubscriptionContainer) | ||
if (subscriptionContainer instanceof internal_1.CallbackSubscriptionContainer) | ||
subscriptionContainer.callback(); | ||
if (subscriptionContainer instanceof ComponentSubscriptionContainer) | ||
if (subscriptionContainer instanceof internal_1.ComponentSubscriptionContainer) | ||
this.agileInstance().integrations.update(subscriptionContainer.component, this.getUpdatedObserverValues(subscriptionContainer)); | ||
subscriptionContainer.updatedSubscribers.clear(); | ||
} | ||
LogCodeManager.logIfTags(['runtime'], '16:01:02', [], subscriptionsToUpdate); | ||
internal_1.LogCodeManager.logIfTags(['runtime'], '16:01:02', [], subscriptionsToUpdate); | ||
} | ||
@@ -130,3 +133,3 @@ getUpdatedObserverValues(subscriptionContainer) { | ||
for (const selectorMethod of selectorMethods) { | ||
if (notEqual(selectorMethod(newValue), selectorMethod(previousValue))) | ||
if (internal_1.notEqual(selectorMethod(newValue), selectorMethod(previousValue))) | ||
return true; | ||
@@ -137,1 +140,2 @@ } | ||
} | ||
exports.Runtime = Runtime; |
@@ -1,3 +0,6 @@ | ||
import { RuntimeJob, LogCodeManager, generateId, defineConfig, } from '../internal'; | ||
export class Observer { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Observer = void 0; | ||
const internal_1 = require("../internal"); | ||
class Observer { | ||
constructor(agileInstance, config = {}) { | ||
@@ -7,3 +10,3 @@ var _a, _b; | ||
this.subscribedTo = new Set(); | ||
config = defineConfig(config, { | ||
config = internal_1.defineConfig(config, { | ||
dependents: [], | ||
@@ -27,3 +30,3 @@ subs: [], | ||
var _a; | ||
config = defineConfig(config, { | ||
config = internal_1.defineConfig(config, { | ||
perform: true, | ||
@@ -37,7 +40,7 @@ background: false, | ||
}); | ||
const job = new RuntimeJob(this, { | ||
const job = new internal_1.RuntimeJob(this, { | ||
force: config.force, | ||
sideEffects: config.sideEffects, | ||
background: config.background, | ||
key: (_a = config.key) !== null && _a !== void 0 ? _a : `${this._key != null ? this._key + '_' : ''}${generateId()}`, | ||
key: (_a = config.key) !== null && _a !== void 0 ? _a : `${this._key != null ? this._key + '_' : ''}${internal_1.generateId()}`, | ||
}); | ||
@@ -49,3 +52,3 @@ this.agileInstance().runtime.ingest(job, { | ||
perform(job) { | ||
LogCodeManager.log('17:03:00'); | ||
internal_1.LogCodeManager.log('17:03:00'); | ||
} | ||
@@ -61,1 +64,2 @@ addDependent(observer) { | ||
} | ||
exports.Observer = Observer; |
@@ -1,3 +0,6 @@ | ||
import { defineConfig } from '../internal'; | ||
export class RuntimeJob { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.RuntimeJob = void 0; | ||
const internal_1 = require("../internal"); | ||
class RuntimeJob { | ||
constructor(observer, config = {}) { | ||
@@ -7,3 +10,3 @@ this.subscriptionContainersToUpdate = new Set(); | ||
this.performed = false; | ||
config = defineConfig(config, { | ||
config = internal_1.defineConfig(config, { | ||
background: false, | ||
@@ -37,1 +40,2 @@ sideEffects: { | ||
} | ||
exports.RuntimeJob = RuntimeJob; |
@@ -1,3 +0,6 @@ | ||
import { SubscriptionContainer, } from '../../../internal'; | ||
export class CallbackSubscriptionContainer extends SubscriptionContainer { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CallbackSubscriptionContainer = void 0; | ||
const internal_1 = require("../../../internal"); | ||
class CallbackSubscriptionContainer extends internal_1.SubscriptionContainer { | ||
constructor(callback, subs, config = {}) { | ||
@@ -8,1 +11,2 @@ super(subs, config); | ||
} | ||
exports.CallbackSubscriptionContainer = CallbackSubscriptionContainer; |
@@ -1,3 +0,6 @@ | ||
import { SubscriptionContainer, } from '../../../internal'; | ||
export class ComponentSubscriptionContainer extends SubscriptionContainer { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ComponentSubscriptionContainer = void 0; | ||
const internal_1 = require("../../../internal"); | ||
class ComponentSubscriptionContainer extends internal_1.SubscriptionContainer { | ||
constructor(component, subs, config = {}) { | ||
@@ -8,1 +11,2 @@ super(subs, config); | ||
} | ||
exports.ComponentSubscriptionContainer = ComponentSubscriptionContainer; |
@@ -1,3 +0,6 @@ | ||
import { defineConfig, generateId, isValidObject, } from '../../../internal'; | ||
export class SubscriptionContainer { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SubscriptionContainer = void 0; | ||
const internal_1 = require("../../../internal"); | ||
class SubscriptionContainer { | ||
constructor(subs, config = {}) { | ||
@@ -8,4 +11,4 @@ var _a, _b, _c, _d; | ||
this.isObjectBased = false; | ||
config = defineConfig(config, { | ||
key: generateId(), | ||
config = internal_1.defineConfig(config, { | ||
key: internal_1.generateId(), | ||
}); | ||
@@ -34,3 +37,3 @@ this.subscribers = new Set(); | ||
for (const branch of path) { | ||
if (!isValidObject(_value, true)) | ||
if (!internal_1.isValidObject(_value, true)) | ||
break; | ||
@@ -60,1 +63,2 @@ _value = _value[branch]; | ||
} | ||
exports.SubscriptionContainer = SubscriptionContainer; |
@@ -1,3 +0,6 @@ | ||
import { ComponentSubscriptionContainer, CallbackSubscriptionContainer, isFunction, removeProperties, LogCodeManager, defineConfig, } from '../../internal'; | ||
export class SubController { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SubController = void 0; | ||
const internal_1 = require("../../internal"); | ||
class SubController { | ||
constructor(agileInstance) { | ||
@@ -10,6 +13,6 @@ this.componentSubs = new Set(); | ||
subscribe(integrationInstance, subs, config = {}) { | ||
config = defineConfig(config, { | ||
config = internal_1.defineConfig(config, { | ||
waitForMount: this.agileInstance().config.waitForMount, | ||
}); | ||
const subscriptionContainer = isFunction(integrationInstance) | ||
const subscriptionContainer = internal_1.isFunction(integrationInstance) | ||
? this.createCallbackSubscriptionContainer(integrationInstance, subs, config) | ||
@@ -33,12 +36,12 @@ : this.createComponentSubscriptionContainer(integrationInstance, subs, config); | ||
}; | ||
if (subscriptionInstance instanceof CallbackSubscriptionContainer) { | ||
if (subscriptionInstance instanceof internal_1.CallbackSubscriptionContainer) { | ||
unsub(subscriptionInstance); | ||
this.callbackSubs.delete(subscriptionInstance); | ||
LogCodeManager.logIfTags(['subscription'], '15:01:00', [], subscriptionInstance); | ||
internal_1.LogCodeManager.logIfTags(['subscription'], '15:01:00', [], subscriptionInstance); | ||
return; | ||
} | ||
if (subscriptionInstance instanceof ComponentSubscriptionContainer) { | ||
if (subscriptionInstance instanceof internal_1.ComponentSubscriptionContainer) { | ||
unsub(subscriptionInstance); | ||
this.componentSubs.delete(subscriptionInstance); | ||
LogCodeManager.logIfTags(['subscription'], '15:01:01', [], subscriptionInstance); | ||
internal_1.LogCodeManager.logIfTags(['subscription'], '15:01:01', [], subscriptionInstance); | ||
return; | ||
@@ -51,3 +54,3 @@ } | ||
this.componentSubs.delete(subContainer); | ||
LogCodeManager.logIfTags(['subscription'], '15:01:01', [], subscriptionInstance); | ||
internal_1.LogCodeManager.logIfTags(['subscription'], '15:01:01', [], subscriptionInstance); | ||
}); | ||
@@ -58,3 +61,3 @@ return; | ||
createComponentSubscriptionContainer(componentInstance, subs, config = {}) { | ||
const componentSubscriptionContainer = new ComponentSubscriptionContainer(componentInstance, subs, removeProperties(config, ['waitForMount'])); | ||
const componentSubscriptionContainer = new internal_1.ComponentSubscriptionContainer(componentInstance, subs, internal_1.removeProperties(config, ['waitForMount'])); | ||
this.componentSubs.add(componentSubscriptionContainer); | ||
@@ -74,10 +77,10 @@ if (config.waitForMount) { | ||
]; | ||
LogCodeManager.logIfTags(['subscription'], '15:01:02', [], componentSubscriptionContainer); | ||
internal_1.LogCodeManager.logIfTags(['subscription'], '15:01:02', [], componentSubscriptionContainer); | ||
return componentSubscriptionContainer; | ||
} | ||
createCallbackSubscriptionContainer(callbackFunction, subs, config = {}) { | ||
const callbackSubscriptionContainer = new CallbackSubscriptionContainer(callbackFunction, subs, removeProperties(config, ['waitForMount'])); | ||
const callbackSubscriptionContainer = new internal_1.CallbackSubscriptionContainer(callbackFunction, subs, internal_1.removeProperties(config, ['waitForMount'])); | ||
this.callbackSubs.add(callbackSubscriptionContainer); | ||
callbackSubscriptionContainer.ready = true; | ||
LogCodeManager.logIfTags(['subscription'], '15:01:03', [], callbackSubscriptionContainer); | ||
internal_1.LogCodeManager.logIfTags(['subscription'], '15:01:03', [], callbackSubscriptionContainer); | ||
return callbackSubscriptionContainer; | ||
@@ -98,1 +101,2 @@ } | ||
} | ||
exports.SubController = SubController; |
@@ -1,2 +0,2 @@ | ||
import { Agile } from './internal'; | ||
import { Agile, Collection, CollectionConfig, Computed, ComputeFunctionType, CreateComputedConfigInterface, CreateStorageConfigInterface, DefaultItem, DependableAgileInstancesType, State, StateConfigInterface, Storage } from './internal'; | ||
/** | ||
@@ -13,2 +13,96 @@ * Shared Agile Instance that is used when no Agile Instance was specified. | ||
export declare function assignSharedAgileInstance(agileInstance: Agile): void; | ||
/** | ||
* Returns a newly created Storage. | ||
* | ||
* A Storage Class serves as an interface to external storages, | ||
* such as the [Async Storage](https://github.com/react-native-async-storage/async-storage) or | ||
* [Local Storage](https://www.w3schools.com/html/html5_webstorage.asp). | ||
* | ||
* It creates the foundation to easily [`persist()`](https://agile-ts.org/docs/core/state/methods#persist) [Agile Sub Instances](https://agile-ts.org/docs/introduction/#agile-sub-instance) | ||
* (like States or Collections) in nearly any external storage. | ||
* | ||
* [Learn more..](https://agile-ts.org/docs/core/agile-instance/methods#createstorage) | ||
* | ||
* @public | ||
* @param config - Configuration object | ||
*/ | ||
export declare function createStorage(config: CreateStorageConfigInterface): Storage; | ||
/** | ||
* Returns a newly created State. | ||
* | ||
* A State manages a piece of Information | ||
* that we need to remember globally at a later point in time. | ||
* While providing a toolkit to use and mutate this piece of Information. | ||
* | ||
* You can create as many global States as you need. | ||
* | ||
* [Learn more..](https://agile-ts.org/docs/core/agile-instance/methods#createstate) | ||
* | ||
* @public | ||
* @param initialValue - Initial value of the State. | ||
* @param config - Configuration object | ||
*/ | ||
export declare function createState<ValueType = any>(initialValue: ValueType, config?: CreateStateConfigInterfaceWithAgile): State<ValueType>; | ||
/** | ||
* Returns a newly created Computed. | ||
* | ||
* A Computed is an extension of the State Class | ||
* that computes its value based on a specified compute function. | ||
* | ||
* The computed value will be cached to avoid unnecessary recomputes | ||
* and is only recomputed when one of its direct dependencies changes. | ||
* | ||
* Direct dependencies can be States and Collections. | ||
* So when, for example, a dependent State value changes, the computed value is recomputed. | ||
* | ||
* [Learn more..](https://agile-ts.org/docs/core/agile-instance/methods#createstate) | ||
* | ||
* @public | ||
* @param computeFunction - Function to compute the computed value. | ||
* @param config - Configuration object | ||
*/ | ||
export declare function createComputed<ComputedValueType = any>(computeFunction: ComputeFunctionType<ComputedValueType>, config?: CreateComputedConfigInterfaceWithAgile): Computed<ComputedValueType>; | ||
/** | ||
* Returns a newly created Computed. | ||
* | ||
* A Computed is an extension of the State Class | ||
* that computes its value based on a specified compute function. | ||
* | ||
* The computed value will be cached to avoid unnecessary recomputes | ||
* and is only recomputed when one of its direct dependencies changes. | ||
* | ||
* Direct dependencies can be States and Collections. | ||
* So when, for example, a dependent State value changes, the computed value is recomputed. | ||
* | ||
* [Learn more..](https://agile-ts.org/docs/core/agile-instance/methods#createcomputed) | ||
* | ||
* @public | ||
* @param computeFunction - Function to compute the computed value. | ||
* @param deps - Hard-coded dependencies on which the Computed Class should depend. | ||
*/ | ||
export declare function createComputed<ComputedValueType = any>(computeFunction: ComputeFunctionType<ComputedValueType>, deps?: Array<DependableAgileInstancesType>): Computed<ComputedValueType>; | ||
/** | ||
* Returns a newly created Collection. | ||
* | ||
* A Collection manages a reactive set of Information | ||
* that we need to remember globally at a later point in time. | ||
* While providing a toolkit to use and mutate this set of Information. | ||
* | ||
* It is designed for arrays of data objects following the same pattern. | ||
* | ||
* Each of these data object must have a unique `primaryKey` to be correctly identified later. | ||
* | ||
* You can create as many global Collections as you need. | ||
* | ||
* [Learn more..](https://agile-ts.org/docs/core/agile-instance/methods#createcollection) | ||
* | ||
* @public | ||
* @param config - Configuration object | ||
* @param agileInstance - Instance of Agile the Collection belongs to. | ||
*/ | ||
export declare function createCollection<DataType extends Object = DefaultItem>(config?: CollectionConfig<DataType>, agileInstance?: Agile): Collection<DataType>; | ||
export interface CreateComputedConfigInterfaceWithAgile extends CreateAgileSubInstanceInterface, CreateComputedConfigInterface { | ||
} | ||
export interface CreateStateConfigInterfaceWithAgile extends CreateAgileSubInstanceInterface, StateConfigInterface { | ||
} | ||
export interface CreateAgileSubInstanceInterface { | ||
@@ -15,0 +109,0 @@ /** |
@@ -1,9 +0,43 @@ | ||
import { Agile, runsOnServer } from './internal'; | ||
let sharedAgileInstance = new Agile({ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createCollection = exports.createComputed = exports.createState = exports.createStorage = exports.assignSharedAgileInstance = exports.shared = void 0; | ||
const internal_1 = require("./internal"); | ||
let sharedAgileInstance = new internal_1.Agile({ | ||
key: 'shared', | ||
localStorage: !runsOnServer(), | ||
localStorage: !internal_1.runsOnServer(), | ||
}); | ||
export { sharedAgileInstance as shared }; | ||
export function assignSharedAgileInstance(agileInstance) { | ||
sharedAgileInstance = agileInstance; | ||
exports.shared = sharedAgileInstance; | ||
function assignSharedAgileInstance(agileInstance) { | ||
exports.shared = sharedAgileInstance = agileInstance; | ||
} | ||
exports.assignSharedAgileInstance = assignSharedAgileInstance; | ||
function createStorage(config) { | ||
return new internal_1.Storage(config); | ||
} | ||
exports.createStorage = createStorage; | ||
function createState(initialValue, config = {}) { | ||
config = internal_1.defineConfig(config, { | ||
agileInstance: sharedAgileInstance, | ||
}); | ||
return new internal_1.State(config.agileInstance, initialValue, internal_1.removeProperties(config, ['agileInstance'])); | ||
} | ||
exports.createState = createState; | ||
function createComputed(computeFunction, configOrDeps) { | ||
let _config = {}; | ||
if (Array.isArray(configOrDeps)) { | ||
_config = internal_1.defineConfig(_config, { | ||
computedDeps: configOrDeps, | ||
}); | ||
} | ||
else { | ||
if (configOrDeps) | ||
_config = configOrDeps; | ||
} | ||
_config = internal_1.defineConfig(_config, { agileInstance: sharedAgileInstance }); | ||
return new internal_1.Computed(_config.agileInstance, computeFunction, internal_1.removeProperties(_config, ['agileInstance'])); | ||
} | ||
exports.createComputed = createComputed; | ||
function createCollection(config, agileInstance = sharedAgileInstance) { | ||
return new internal_1.Collection(agileInstance, config); | ||
} | ||
exports.createCollection = createCollection; |
/// <reference types="node" /> | ||
import { Agile, StorageKey, StateObserver, StatePersistent, Observer, PersistentKey, StateIngestConfigInterface, CreateAgileSubInstanceInterface } from '../internal'; | ||
import { Agile, StorageKey, StateObserver, StatePersistent, Observer, PersistentKey, StateIngestConfigInterface } from '../internal'; | ||
export declare class State<ValueType = any> { | ||
agileInstance: () => Agile; | ||
_key?: StateKey; | ||
valueType?: string; | ||
isSet: boolean; | ||
@@ -21,5 +20,2 @@ isPlaceholder: boolean; | ||
persistent: StatePersistent | undefined; | ||
watchers: { | ||
[key: string]: StateWatcherCallback<ValueType>; | ||
}; | ||
currentInterval?: NodeJS.Timer | number; | ||
@@ -110,13 +106,2 @@ /** | ||
/** | ||
* Assigns a primitive type to the State | ||
* which constrains the State value on the specified type | ||
* to ensure basic typesafety in Javascript. | ||
* | ||
* [Learn more..](https://agile-ts.org/docs/core/state/methods/#type) | ||
* | ||
* @public | ||
* @param type - Primitive type the State value must follow (`String`, `Boolean`, `Array`, `Object`, `Number`). | ||
*/ | ||
type(type: any): this; | ||
/** | ||
* Undoes the latest State value change. | ||
@@ -185,12 +170,2 @@ * | ||
/** | ||
* Returns a boolean indicating whether a watcher callback with the specified `key` | ||
* exists in the State or not. | ||
* | ||
* [Learn more..](https://agile-ts.org/docs/core/state/methods/#haswatcher) | ||
* | ||
* @public | ||
* @param key - Key/Name identifier of the watcher callback to be checked for existence. | ||
*/ | ||
hasWatcher(key: string): boolean; | ||
/** | ||
* Fires on the initial State value assignment and then destroys itself. | ||
@@ -367,10 +342,2 @@ * | ||
/** | ||
* Returns a boolean indicating whether the passed value | ||
* is of the before defined State `valueType` or not. | ||
* | ||
* @internal | ||
* @param value - Value to be checked for the correct type. | ||
*/ | ||
hasCorrectType(value: any): boolean; | ||
/** | ||
* Returns the persistable value of the State. | ||
@@ -382,20 +349,2 @@ * | ||
} | ||
/** | ||
* Returns a newly created State. | ||
* | ||
* A State manages a piece of Information | ||
* that we need to remember globally at a later point in time. | ||
* While providing a toolkit to use and mutate this piece of Information. | ||
* | ||
* You can create as many global States as you need. | ||
* | ||
* [Learn more..](https://agile-ts.org/docs/core/agile-instance/methods#createstate) | ||
* | ||
* @public | ||
* @param initialValue - Initial value of the State. | ||
* @param config - Configuration object | ||
*/ | ||
export declare function createState<ValueType = any>(initialValue: ValueType, config?: CreateStateConfigInterfaceWithAgile): State<ValueType>; | ||
export interface CreateStateConfigInterfaceWithAgile extends CreateAgileSubInstanceInterface, StateConfigInterface { | ||
} | ||
export declare type StateKey = string | number; | ||
@@ -402,0 +351,0 @@ export interface StateObserversInterface<ValueType = any> { |
@@ -1,3 +0,6 @@ | ||
import { copy, flatMerge, isValidObject, StateObserver, StatePersistent, equal, isFunction, notEqual, generateId, ComputedTracker, removeProperties, LogCodeManager, defineConfig, shared, } from '../internal'; | ||
export class State { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.State = void 0; | ||
const internal_1 = require("../internal"); | ||
class State { | ||
constructor(agileInstance, initialValue, config = {}) { | ||
@@ -9,4 +12,3 @@ this.isSet = false; | ||
this.isPersisted = false; | ||
this.watchers = {}; | ||
config = defineConfig(config, { | ||
config = internal_1.defineConfig(config, { | ||
dependents: [], | ||
@@ -17,10 +19,10 @@ isPlaceholder: false, | ||
this._key = config.key; | ||
this.observers['value'] = new StateObserver(this, { | ||
this.observers['value'] = new internal_1.StateObserver(this, { | ||
key: config.key, | ||
dependents: config.dependents, | ||
}); | ||
this.initialStateValue = copy(initialValue); | ||
this._value = copy(initialValue); | ||
this.previousStateValue = copy(initialValue); | ||
this.nextStateValue = copy(initialValue); | ||
this.initialStateValue = internal_1.copy(initialValue); | ||
this._value = internal_1.copy(initialValue); | ||
this.previousStateValue = internal_1.copy(initialValue); | ||
this.nextStateValue = internal_1.copy(initialValue); | ||
this.isPlaceholder = true; | ||
@@ -37,4 +39,4 @@ this.computeExistsMethod = (v) => { | ||
get value() { | ||
ComputedTracker.tracked(this.observers['value']); | ||
return copy(this._value); | ||
internal_1.ComputedTracker.tracked(this.observers['value']); | ||
return internal_1.copy(this._value); | ||
} | ||
@@ -58,16 +60,8 @@ set key(value) { | ||
set(value, config = {}) { | ||
config = defineConfig(config, { | ||
config = internal_1.defineConfig(config, { | ||
force: false, | ||
}); | ||
const _value = isFunction(value) | ||
? value(copy(this._value)) | ||
const _value = internal_1.isFunction(value) | ||
? value(internal_1.copy(this._value)) | ||
: value; | ||
if (!this.hasCorrectType(_value)) { | ||
LogCodeManager.log(config.force ? '14:02:00' : '14:03:00', [ | ||
typeof _value, | ||
this.valueType, | ||
]); | ||
if (!config.force) | ||
return this; | ||
} | ||
this.observers['value'].ingestValue(_value, config); | ||
@@ -80,11 +74,2 @@ return this; | ||
} | ||
type(type) { | ||
const supportedTypes = ['String', 'Boolean', 'Array', 'Object', 'Number']; | ||
if (!supportedTypes.includes(type.name)) { | ||
LogCodeManager.log('14:03:01', [type]); | ||
return this; | ||
} | ||
this.valueType = type.name.toLowerCase(); | ||
return this; | ||
} | ||
undo(config = {}) { | ||
@@ -99,11 +84,11 @@ this.set(this.previousStateValue, config); | ||
patch(targetWithChanges, config = {}) { | ||
config = defineConfig(config, { | ||
config = internal_1.defineConfig(config, { | ||
addNewProperties: true, | ||
}); | ||
if (!isValidObject(this.nextStateValue, true)) { | ||
LogCodeManager.log('14:03:02'); | ||
if (!internal_1.isValidObject(this.nextStateValue, true)) { | ||
internal_1.LogCodeManager.log('14:03:02'); | ||
return this; | ||
} | ||
if (!isValidObject(targetWithChanges, true)) { | ||
LogCodeManager.log('00:03:01', ['TargetWithChanges', 'object']); | ||
if (!internal_1.isValidObject(targetWithChanges, true)) { | ||
internal_1.LogCodeManager.log('00:03:01', ['TargetWithChanges', 'object']); | ||
return this; | ||
@@ -119,13 +104,13 @@ } | ||
else { | ||
this.nextStateValue = flatMerge(this.nextStateValue, targetWithChanges, { addNewProperties: config.addNewProperties }); | ||
this.nextStateValue = internal_1.flatMerge(this.nextStateValue, targetWithChanges, { addNewProperties: config.addNewProperties }); | ||
} | ||
this.ingest(removeProperties(config, ['addNewProperties'])); | ||
this.ingest(internal_1.removeProperties(config, ['addNewProperties'])); | ||
return this; | ||
} | ||
watch(keyOrCallback, callback) { | ||
const generateKey = isFunction(keyOrCallback); | ||
const generateKey = internal_1.isFunction(keyOrCallback); | ||
let _callback; | ||
let key; | ||
if (generateKey) { | ||
key = generateId(); | ||
key = internal_1.generateId(); | ||
_callback = keyOrCallback; | ||
@@ -137,16 +122,15 @@ } | ||
} | ||
if (!isFunction(_callback)) { | ||
LogCodeManager.log('00:03:01', ['Watcher Callback', 'function']); | ||
if (!internal_1.isFunction(_callback)) { | ||
internal_1.LogCodeManager.log('00:03:01', ['Watcher Callback', 'function']); | ||
return this; | ||
} | ||
this.watchers[key] = _callback; | ||
this.addSideEffect(key, (instance) => { | ||
_callback(instance.value, key); | ||
}, { weight: 0 }); | ||
return generateKey ? key : this; | ||
} | ||
removeWatcher(key) { | ||
delete this.watchers[key]; | ||
this.removeSideEffect(key); | ||
return this; | ||
} | ||
hasWatcher(key) { | ||
return !!this.watchers[key]; | ||
} | ||
onInaugurated(callback) { | ||
@@ -156,3 +140,3 @@ const watcherKey = 'InauguratedWatcherKey'; | ||
callback(value, key); | ||
this.removeWatcher(watcherKey); | ||
this.removeSideEffect(watcherKey); | ||
}); | ||
@@ -164,3 +148,3 @@ return this; | ||
let key; | ||
if (isValidObject(keyOrConfig)) { | ||
if (internal_1.isValidObject(keyOrConfig)) { | ||
_config = keyOrConfig; | ||
@@ -173,3 +157,3 @@ key = this._key; | ||
} | ||
_config = defineConfig(_config, { | ||
_config = internal_1.defineConfig(_config, { | ||
loadValue: true, | ||
@@ -181,3 +165,3 @@ storageKeys: [], | ||
return this; | ||
this.persistent = new StatePersistent(this, { | ||
this.persistent = new internal_1.StatePersistent(this, { | ||
instantiate: _config.loadValue, | ||
@@ -193,4 +177,4 @@ storageKeys: _config.storageKeys, | ||
return this; | ||
if (!isFunction(callback)) { | ||
LogCodeManager.log('00:03:01', ['OnLoad Callback', 'function']); | ||
if (!internal_1.isFunction(callback)) { | ||
internal_1.LogCodeManager.log('00:03:01', ['OnLoad Callback', 'function']); | ||
return this; | ||
@@ -204,8 +188,8 @@ } | ||
interval(handler, delay) { | ||
if (!isFunction(handler)) { | ||
LogCodeManager.log('00:03:01', ['Interval Callback', 'function']); | ||
if (!internal_1.isFunction(handler)) { | ||
internal_1.LogCodeManager.log('00:03:01', ['Interval Callback', 'function']); | ||
return this; | ||
} | ||
if (this.currentInterval) { | ||
LogCodeManager.log('14:03:03', [], this.currentInterval); | ||
internal_1.LogCodeManager.log('14:03:03', [], this.currentInterval); | ||
return this; | ||
@@ -228,4 +212,4 @@ } | ||
computeExists(method) { | ||
if (!isFunction(method)) { | ||
LogCodeManager.log('00:03:01', ['Compute Exists Method', 'function']); | ||
if (!internal_1.isFunction(method)) { | ||
internal_1.LogCodeManager.log('00:03:01', ['Compute Exists Method', 'function']); | ||
return this; | ||
@@ -237,4 +221,4 @@ } | ||
computeValue(method) { | ||
if (!isFunction(method)) { | ||
LogCodeManager.log('00:03:01', ['Compute Value Method', 'function']); | ||
if (!internal_1.isFunction(method)) { | ||
internal_1.LogCodeManager.log('00:03:01', ['Compute Value Method', 'function']); | ||
return this; | ||
@@ -247,6 +231,6 @@ } | ||
is(value) { | ||
return equal(value, this.value); | ||
return internal_1.equal(value, this.value); | ||
} | ||
isNot(value) { | ||
return notEqual(value, this.value); | ||
return internal_1.notEqual(value, this.value); | ||
} | ||
@@ -269,3 +253,3 @@ invert() { | ||
default: | ||
LogCodeManager.log('14:03:04', [typeof this.nextStateValue]); | ||
internal_1.LogCodeManager.log('14:03:04', [typeof this.nextStateValue]); | ||
} | ||
@@ -275,7 +259,7 @@ return this; | ||
addSideEffect(key, callback, config = {}) { | ||
config = defineConfig(config, { | ||
config = internal_1.defineConfig(config, { | ||
weight: 10, | ||
}); | ||
if (!isFunction(callback)) { | ||
LogCodeManager.log('00:03:01', ['Side Effect Callback', 'function']); | ||
if (!internal_1.isFunction(callback)) { | ||
internal_1.LogCodeManager.log('00:03:01', ['Side Effect Callback', 'function']); | ||
return this; | ||
@@ -296,8 +280,2 @@ } | ||
} | ||
hasCorrectType(value) { | ||
if (!this.valueType) | ||
return true; | ||
const type = typeof value; | ||
return type === this.valueType; | ||
} | ||
getPersistableValue() { | ||
@@ -307,7 +285,2 @@ return this._value; | ||
} | ||
export function createState(initialValue, config = {}) { | ||
config = defineConfig(config, { | ||
agileInstance: shared, | ||
}); | ||
return new State(config.agileInstance, initialValue, removeProperties(config, ['agileInstance'])); | ||
} | ||
exports.State = State; |
@@ -1,13 +0,16 @@ | ||
import { Observer, Computed, copy, equal, notEqual, isFunction, StateRuntimeJob, createArrayFromObject, generateId, defineConfig, } from '../internal'; | ||
export class StateObserver extends Observer { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.StateObserver = void 0; | ||
const internal_1 = require("../internal"); | ||
class StateObserver extends internal_1.Observer { | ||
constructor(state, config = {}) { | ||
super(state.agileInstance(), defineConfig(config, { | ||
super(state.agileInstance(), internal_1.defineConfig(config, { | ||
value: state._value, | ||
})); | ||
this.state = () => state; | ||
this.nextStateValue = copy(state._value); | ||
this.nextStateValue = internal_1.copy(state._value); | ||
} | ||
ingest(config = {}) { | ||
const state = this.state(); | ||
if (state instanceof Computed) { | ||
if (state.isComputed) { | ||
state.compute().then((result) => { | ||
@@ -24,3 +27,3 @@ this.ingestValue(result, config); | ||
const state = this.state(); | ||
config = defineConfig(config, { | ||
config = internal_1.defineConfig(config, { | ||
perform: true, | ||
@@ -42,7 +45,7 @@ background: false, | ||
this.nextStateValue = state.computeValueMethod | ||
? copy(state.computeValueMethod(newStateValue)) | ||
: copy(newStateValue); | ||
if (equal(state._value, this.nextStateValue) && !config.force) | ||
? internal_1.copy(state.computeValueMethod(newStateValue)) | ||
: internal_1.copy(newStateValue); | ||
if (internal_1.equal(state._value, this.nextStateValue) && !config.force) | ||
return; | ||
const job = new StateRuntimeJob(this, { | ||
const job = new internal_1.StateRuntimeJob(this, { | ||
storage: config.storage, | ||
@@ -53,3 +56,3 @@ sideEffects: config.sideEffects, | ||
overwrite: config.overwrite, | ||
key: (_a = config.key) !== null && _a !== void 0 ? _a : `${this._key != null ? this._key + '_' : ''}${generateId()}_value`, | ||
key: (_a = config.key) !== null && _a !== void 0 ? _a : `${this._key != null ? this._key + '_' : ''}${internal_1.generateId()}_value`, | ||
maxTriesToUpdate: config.maxTriesToUpdate, | ||
@@ -64,14 +67,14 @@ }); | ||
const state = observer.state(); | ||
state.previousStateValue = copy(state._value); | ||
state._value = copy(observer.nextStateValue); | ||
state.nextStateValue = copy(observer.nextStateValue); | ||
state.previousStateValue = internal_1.copy(state._value); | ||
state._value = internal_1.copy(observer.nextStateValue); | ||
state.nextStateValue = internal_1.copy(observer.nextStateValue); | ||
if (job.config.overwrite) { | ||
state.initialStateValue = copy(state._value); | ||
state.previousStateValue = copy(state._value); | ||
state.initialStateValue = internal_1.copy(state._value); | ||
state.previousStateValue = internal_1.copy(state._value); | ||
state.isPlaceholder = false; | ||
} | ||
state.isSet = notEqual(state._value, state.initialStateValue); | ||
state.isSet = internal_1.notEqual(state._value, state.initialStateValue); | ||
this.sideEffects(job); | ||
job.observer.previousValue = copy(observer.value); | ||
job.observer.value = copy(state._value); | ||
job.observer.previousValue = internal_1.copy(observer.value); | ||
job.observer.value = internal_1.copy(state._value); | ||
} | ||
@@ -81,7 +84,4 @@ sideEffects(job) { | ||
const state = job.observer.state(); | ||
for (const watcherKey in state.watchers) | ||
if (isFunction(state.watchers[watcherKey])) | ||
state.watchers[watcherKey](state._value, watcherKey); | ||
if ((_b = (_a = job.config) === null || _a === void 0 ? void 0 : _a.sideEffects) === null || _b === void 0 ? void 0 : _b.enabled) { | ||
const sideEffectArray = createArrayFromObject(state.sideEffects); | ||
const sideEffectArray = internal_1.createArrayFromObject(state.sideEffects); | ||
sideEffectArray.sort(function (a, b) { | ||
@@ -91,3 +91,3 @@ return b.instance.weight - a.instance.weight; | ||
for (const sideEffect of sideEffectArray) { | ||
if (isFunction(sideEffect.instance.callback)) { | ||
if (internal_1.isFunction(sideEffect.instance.callback)) { | ||
if (!((_c = job.config.sideEffects.exclude) === null || _c === void 0 ? void 0 : _c.includes(sideEffect.key))) | ||
@@ -100,1 +100,2 @@ sideEffect.instance.callback(job.observer.state(), job.config); | ||
} | ||
exports.StateObserver = StateObserver; |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -10,4 +11,6 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
import { defineConfig, Persistent, } from '../internal'; | ||
export class StatePersistent extends Persistent { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.StatePersistent = void 0; | ||
const internal_1 = require("../internal"); | ||
class StatePersistent extends internal_1.Persistent { | ||
constructor(state, config = {}) { | ||
@@ -17,3 +20,3 @@ super(state.agileInstance(), { | ||
}); | ||
config = defineConfig(config, { | ||
config = internal_1.defineConfig(config, { | ||
instantiate: true, | ||
@@ -101,2 +104,3 @@ storageKeys: [], | ||
} | ||
exports.StatePersistent = StatePersistent; | ||
StatePersistent.storeValueSideEffectKey = 'rebuildStateStorageValue'; |
@@ -1,6 +0,9 @@ | ||
import { defineConfig, RuntimeJob, } from '../internal'; | ||
export class StateRuntimeJob extends RuntimeJob { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.StateRuntimeJob = void 0; | ||
const internal_1 = require("../internal"); | ||
class StateRuntimeJob extends internal_1.RuntimeJob { | ||
constructor(observer, config = {}) { | ||
super(observer, config); | ||
config = defineConfig(config, { | ||
config = internal_1.defineConfig(config, { | ||
background: false, | ||
@@ -26,1 +29,2 @@ sideEffects: { | ||
} | ||
exports.StateRuntimeJob = StateRuntimeJob; |
@@ -1,3 +0,6 @@ | ||
import { Storage, notEqual, LogCodeManager, defineConfig, } from '../internal'; | ||
export class Storages { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Storages = void 0; | ||
const internal_1 = require("../internal"); | ||
class Storages { | ||
constructor(agileInstance, config = {}) { | ||
@@ -7,3 +10,3 @@ this.storages = {}; | ||
this.agileInstance = () => agileInstance; | ||
config = defineConfig(config, { | ||
config = internal_1.defineConfig(config, { | ||
localStorage: false, | ||
@@ -18,6 +21,6 @@ defaultStorageKey: null, | ||
if (!Storages.localStorageAvailable()) { | ||
LogCodeManager.log('11:02:00'); | ||
internal_1.LogCodeManager.log('11:02:00'); | ||
return false; | ||
} | ||
const _localStorage = new Storage({ | ||
const _localStorage = new internal_1.Storage({ | ||
key: 'localStorage', | ||
@@ -34,9 +37,9 @@ async: false, | ||
register(storage, config = {}) { | ||
const hasRegisteredAnyStorage = notEqual(this.storages, {}); | ||
const hasRegisteredAnyStorage = internal_1.notEqual(this.storages, {}); | ||
if (Object.prototype.hasOwnProperty.call(this.storages, storage.key)) { | ||
LogCodeManager.log('11:03:00', [storage.key]); | ||
internal_1.LogCodeManager.log('11:03:00', [storage.key]); | ||
return false; | ||
} | ||
if (!hasRegisteredAnyStorage && config.default === false) | ||
LogCodeManager.log('11:02:01'); | ||
internal_1.LogCodeManager.log('11:02:01'); | ||
if (!hasRegisteredAnyStorage) | ||
@@ -61,3 +64,3 @@ config.default = true; | ||
}); | ||
LogCodeManager.log('13:00:00', [storage.key], storage); | ||
internal_1.LogCodeManager.log('13:00:00', [storage.key], storage); | ||
return true; | ||
@@ -70,7 +73,7 @@ } | ||
if (!storage) { | ||
LogCodeManager.log('11:03:01', [storageKey]); | ||
internal_1.LogCodeManager.log('11:03:01', [storageKey]); | ||
return undefined; | ||
} | ||
if (!storage.ready) { | ||
LogCodeManager.log('11:03:02', [storageKey]); | ||
internal_1.LogCodeManager.log('11:03:02', [storageKey]); | ||
return undefined; | ||
@@ -82,3 +85,3 @@ } | ||
if (!this.hasStorage()) { | ||
LogCodeManager.log('11:03:03'); | ||
internal_1.LogCodeManager.log('11:03:03'); | ||
return Promise.resolve(undefined); | ||
@@ -97,3 +100,3 @@ } | ||
if (!this.hasStorage()) { | ||
LogCodeManager.log('11:03:04'); | ||
internal_1.LogCodeManager.log('11:03:04'); | ||
return; | ||
@@ -112,3 +115,3 @@ } | ||
if (!this.hasStorage()) { | ||
LogCodeManager.log('11:03:05'); | ||
internal_1.LogCodeManager.log('11:03:05'); | ||
return; | ||
@@ -125,3 +128,3 @@ } | ||
hasStorage() { | ||
return notEqual(this.storages, {}); | ||
return internal_1.notEqual(this.storages, {}); | ||
} | ||
@@ -139,1 +142,2 @@ static localStorageAvailable() { | ||
} | ||
exports.Storages = Storages; |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -10,4 +11,6 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
import { copy, defineConfig, LogCodeManager, } from '../internal'; | ||
export class Persistent { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Persistent = void 0; | ||
const internal_1 = require("../internal"); | ||
class Persistent { | ||
constructor(agileInstance, config = {}) { | ||
@@ -19,3 +22,3 @@ this.ready = false; | ||
this._key = Persistent.placeHolderKey; | ||
config = defineConfig(config, { | ||
config = internal_1.defineConfig(config, { | ||
instantiate: true, | ||
@@ -68,7 +71,7 @@ storageKeys: [], | ||
if (this._key === Persistent.placeHolderKey) { | ||
LogCodeManager.log('12:03:00'); | ||
internal_1.LogCodeManager.log('12:03:00'); | ||
isValid = false; | ||
} | ||
if (this.config.defaultStorageKey == null || this.storageKeys.length <= 0) { | ||
LogCodeManager.log('12:03:01'); | ||
internal_1.LogCodeManager.log('12:03:01'); | ||
isValid = false; | ||
@@ -78,3 +81,3 @@ } | ||
if (!this.agileInstance().storages.storages[key]) { | ||
LogCodeManager.log('12:03:02', [this._key, key]); | ||
internal_1.LogCodeManager.log('12:03:02', [this._key, key]); | ||
isValid = false; | ||
@@ -88,3 +91,3 @@ } | ||
const storages = this.agileInstance().storages; | ||
const _storageKeys = copy(storageKeys); | ||
const _storageKeys = internal_1.copy(storageKeys); | ||
if (defaultStorageKey != null && !_storageKeys.includes(defaultStorageKey)) | ||
@@ -115,3 +118,3 @@ _storageKeys.push(defaultStorageKey); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
LogCodeManager.log('00:03:00', ['loadPersistedValue', 'Persistent']); | ||
internal_1.LogCodeManager.log('00:03:00', ['loadPersistedValue', 'Persistent']); | ||
return false; | ||
@@ -122,3 +125,3 @@ }); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
LogCodeManager.log('00:03:00', ['persistValue', 'Persistent']); | ||
internal_1.LogCodeManager.log('00:03:00', ['persistValue', 'Persistent']); | ||
return false; | ||
@@ -129,3 +132,3 @@ }); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
LogCodeManager.log('00:03:00', ['removePersistedValue', 'Persistent']); | ||
internal_1.LogCodeManager.log('00:03:00', ['removePersistedValue', 'Persistent']); | ||
return false; | ||
@@ -138,2 +141,3 @@ }); | ||
} | ||
exports.Persistent = Persistent; | ||
Persistent.placeHolderKey = '__THIS_IS_A_PLACEHOLDER__'; |
@@ -69,18 +69,2 @@ export declare class Storage { | ||
} | ||
/** | ||
* Returns a newly created Storage. | ||
* | ||
* A Storage Class serves as an interface to external storages, | ||
* such as the [Async Storage](https://github.com/react-native-async-storage/async-storage) or | ||
* [Local Storage](https://www.w3schools.com/html/html5_webstorage.asp). | ||
* | ||
* It creates the foundation to easily [`persist()`](https://agile-ts.org/docs/core/state/methods#persist) [Agile Sub Instances](https://agile-ts.org/docs/introduction/#agile-sub-instance) | ||
* (like States or Collections) in nearly any external storage. | ||
* | ||
* [Learn more..](https://agile-ts.org/docs/core/agile-instance/methods#createstorage) | ||
* | ||
* @public | ||
* @param config - Configuration object | ||
*/ | ||
export declare function createStorage(config: CreateStorageConfigInterface): Storage; | ||
export declare type StorageKey = string | number; | ||
@@ -87,0 +71,0 @@ export declare type StorageItemKey = string | number; |
@@ -1,6 +0,9 @@ | ||
import { isJsonString, isAsyncFunction, isFunction, LogCodeManager, defineConfig, } from '../internal'; | ||
export class Storage { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Storage = void 0; | ||
const internal_1 = require("../internal"); | ||
class Storage { | ||
constructor(config) { | ||
this.ready = false; | ||
config = defineConfig(config, { | ||
config = internal_1.defineConfig(config, { | ||
prefix: 'agile', | ||
@@ -18,5 +21,5 @@ async: false, | ||
return; | ||
if (isAsyncFunction(this.methods.get) || | ||
isAsyncFunction(this.methods.set) || | ||
isAsyncFunction(this.methods.remove)) | ||
if (internal_1.isAsyncFunction(this.methods.get) || | ||
internal_1.isAsyncFunction(this.methods.set) || | ||
internal_1.isAsyncFunction(this.methods.remove)) | ||
this.config.async = true; | ||
@@ -26,12 +29,12 @@ } | ||
var _a, _b, _c; | ||
if (!isFunction((_a = this.methods) === null || _a === void 0 ? void 0 : _a.get)) { | ||
LogCodeManager.log('13:03:00', ['get']); | ||
if (!internal_1.isFunction((_a = this.methods) === null || _a === void 0 ? void 0 : _a.get)) { | ||
internal_1.LogCodeManager.log('13:03:00', ['get']); | ||
return false; | ||
} | ||
if (!isFunction((_b = this.methods) === null || _b === void 0 ? void 0 : _b.set)) { | ||
LogCodeManager.log('13:03:00', ['set']); | ||
if (!internal_1.isFunction((_b = this.methods) === null || _b === void 0 ? void 0 : _b.set)) { | ||
internal_1.LogCodeManager.log('13:03:00', ['set']); | ||
return false; | ||
} | ||
if (!isFunction((_c = this.methods) === null || _c === void 0 ? void 0 : _c.remove)) { | ||
LogCodeManager.log('13:03:00', ['remove']); | ||
if (!internal_1.isFunction((_c = this.methods) === null || _c === void 0 ? void 0 : _c.remove)) { | ||
internal_1.LogCodeManager.log('13:03:00', ['remove']); | ||
return false; | ||
@@ -44,7 +47,7 @@ } | ||
return undefined; | ||
if (isAsyncFunction(this.methods.get)) | ||
LogCodeManager.log('13:02:00'); | ||
if (internal_1.isAsyncFunction(this.methods.get)) | ||
internal_1.LogCodeManager.log('13:02:00'); | ||
const res = this.methods.get(this.getStorageKey(key)); | ||
const _res = isJsonString(res) ? JSON.parse(res) : res; | ||
LogCodeManager.logIfTags(['storage'], '13:01:00', [this.key, this.getStorageKey(key)], _res); | ||
const _res = internal_1.isJsonString(res) ? JSON.parse(res) : res; | ||
internal_1.LogCodeManager.logIfTags(['storage'], '13:01:00', [this.key, this.getStorageKey(key)], _res); | ||
return _res; | ||
@@ -55,3 +58,3 @@ } | ||
return Promise.resolve(undefined); | ||
if (!isAsyncFunction(this.methods.get)) | ||
if (!internal_1.isAsyncFunction(this.methods.get)) | ||
return Promise.resolve(this.normalGet(key)); | ||
@@ -61,4 +64,4 @@ return new Promise((resolve, reject) => { | ||
(_a = this.methods) === null || _a === void 0 ? void 0 : _a.get(this.getStorageKey(key)).then((res) => { | ||
const _res = isJsonString(res) ? JSON.parse(res) : res; | ||
LogCodeManager.logIfTags(['storage'], '13:01:00', [this.key, this.getStorageKey(key)], _res); | ||
const _res = internal_1.isJsonString(res) ? JSON.parse(res) : res; | ||
internal_1.LogCodeManager.logIfTags(['storage'], '13:01:00', [this.key, this.getStorageKey(key)], _res); | ||
resolve(_res); | ||
@@ -71,3 +74,3 @@ }).catch(reject); | ||
return; | ||
LogCodeManager.logIfTags(['storage'], '13:01:01', [ | ||
internal_1.LogCodeManager.logIfTags(['storage'], '13:01:01', [ | ||
this.key, | ||
@@ -81,3 +84,3 @@ this.getStorageKey(key), | ||
return; | ||
LogCodeManager.logIfTags(['storage'], '13:01:02', [ | ||
internal_1.LogCodeManager.logIfTags(['storage'], '13:01:02', [ | ||
this.key, | ||
@@ -94,4 +97,2 @@ this.getStorageKey(key), | ||
} | ||
export function createStorage(config) { | ||
return new Storage(config); | ||
} | ||
exports.Storage = Storage; |
@@ -1,6 +0,9 @@ | ||
import { Agile, Observer, normalizeArray, isFunction, LogCodeManager, shared, } from './internal'; | ||
export function getAgileInstance(instance) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.runsOnServer = exports.globalBind = exports.optionalRequire = exports.extractRelevantObservers = exports.extractObservers = exports.getAgileInstance = void 0; | ||
const internal_1 = require("./internal"); | ||
function getAgileInstance(instance) { | ||
try { | ||
if (instance) { | ||
const _agileInstance = isFunction(instance['agileInstance']) | ||
const _agileInstance = internal_1.isFunction(instance['agileInstance']) | ||
? instance['agileInstance']() | ||
@@ -11,15 +14,16 @@ : instance['agileInstance']; | ||
} | ||
if (shared instanceof Agile) { | ||
return shared; | ||
if (internal_1.shared instanceof internal_1.Agile) { | ||
return internal_1.shared; | ||
} | ||
return globalThis[Agile.globalKey]; | ||
return globalThis[internal_1.Agile.globalKey]; | ||
} | ||
catch (e) { | ||
LogCodeManager.log('20:03:00', [], instance); | ||
internal_1.LogCodeManager.log('20:03:00', [], instance); | ||
} | ||
return undefined; | ||
} | ||
export function extractObservers(instances) { | ||
exports.getAgileInstance = getAgileInstance; | ||
function extractObservers(instances) { | ||
const observers = []; | ||
const tempInstancesArray = normalizeArray(instances, { | ||
const tempInstancesArray = internal_1.normalizeArray(instances, { | ||
createUndefinedArray: true, | ||
@@ -37,3 +41,3 @@ }); | ||
} | ||
if (instance['observer'] && instance['observer'] instanceof Observer) { | ||
if (instance['observer'] && instance['observer'] instanceof internal_1.Observer) { | ||
observers.push({ value: instance['observer'] }); | ||
@@ -45,3 +49,3 @@ continue; | ||
for (const key in instance['observers']) { | ||
if (instance['observers'][key] instanceof Observer) { | ||
if (instance['observers'][key] instanceof internal_1.Observer) { | ||
extractedObservers[key] = instance['observers'][key]; | ||
@@ -53,3 +57,3 @@ } | ||
} | ||
if (instance instanceof Observer) { | ||
if (instance instanceof internal_1.Observer) { | ||
observers.push({ value: instance }); | ||
@@ -62,3 +66,4 @@ continue; | ||
} | ||
export function extractRelevantObservers(instances, observerType) { | ||
exports.extractObservers = extractObservers; | ||
function extractRelevantObservers(instances, observerType) { | ||
var _a; | ||
@@ -81,3 +86,4 @@ const depsWithIndicator = {}; | ||
} | ||
export function optionalRequire(moduleName, error = true) { | ||
exports.extractRelevantObservers = extractRelevantObservers; | ||
function optionalRequire(moduleName, error = true) { | ||
let requiredPackage = null; | ||
@@ -89,3 +95,3 @@ try { | ||
if (error) { | ||
LogCodeManager.log('20:03:02', [moduleName]); | ||
internal_1.LogCodeManager.log('20:03:02', [moduleName]); | ||
console.log(e); | ||
@@ -96,3 +102,4 @@ } | ||
} | ||
export function globalBind(key, instance, overwrite = false) { | ||
exports.optionalRequire = optionalRequire; | ||
function globalBind(key, instance, overwrite = false) { | ||
try { | ||
@@ -109,7 +116,8 @@ if (overwrite) { | ||
catch (e) { | ||
LogCodeManager.log('20:03:01', [key]); | ||
internal_1.LogCodeManager.log('20:03:01', [key]); | ||
} | ||
return false; | ||
} | ||
export const runsOnServer = () => { | ||
exports.globalBind = globalBind; | ||
const runsOnServer = () => { | ||
return !(typeof window !== 'undefined' && | ||
@@ -119,1 +127,2 @@ typeof window.document !== 'undefined' && | ||
}; | ||
exports.runsOnServer = runsOnServer; |
{ | ||
"name": "@agile-ts/core", | ||
"version": "0.2.0-alpha.1", | ||
"version": "0.2.0-alpha.2", | ||
"author": "BennoDev", | ||
@@ -27,6 +27,9 @@ "license": "MIT", | ||
"main": "dist/index.js", | ||
"module": "dist/esm/index.js", | ||
"types": "dist/index.d.ts", | ||
"scripts": { | ||
"build": "tsc", | ||
"prepare": "tsc && tsc -p ./tsconfig.production.json", | ||
"build": "yarn run build:esm && yarn run build:cjs", | ||
"prepare": "yarn run build", | ||
"build:esm": "tsc -p ./tsconfig.esm.json", | ||
"build:cjs": "tsc -p ./tsconfig.json && tsc -p ./tsconfig.production.json", | ||
"dev:publish": "yalc publish", | ||
@@ -37,7 +40,8 @@ "dev:push": "yalc push", | ||
"release": "node ./scripts/prepublish.js && yarn run prepare", | ||
"preview": "npm pack", | ||
"pack": "npm pack", | ||
"test": "jest", | ||
"test:coverage": "jest --coverage", | ||
"lint": "eslint src/**/*", | ||
"size": "yarn run build && size-limit" | ||
"size": "yarn run build && size-limit", | ||
"release:manual": "yarn run prepare && yarn run release && npm publish && git checkout README.md" | ||
}, | ||
@@ -44,0 +48,0 @@ "devDependencies": { |
431036
94
10067
2