@agile-ts/core
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -6,4 +6,12 @@ # Change Log | ||
## [0.0.5](https://github.com/agile-ts/agile/compare/v0.0.4...v0.0.5) (2020-11-05) | ||
**Note:** Version bump only for package @agile-ts/core | ||
## 0.0.4 (2020-11-03) | ||
**Note:** Version bump only for package @agile-ts/core |
@@ -1,2 +0,2 @@ | ||
import { Agile, Item, Group, GroupKey, Selector, SelectorKey, StateKey, StorageKey, GroupConfigInterface, CollectionPersistent } from "../internal"; | ||
import { Agile, Item, Group, GroupKey, Selector, SelectorKey, StateKey, StorageKey, GroupConfigInterface, CollectionPersistent, GroupAddConfig } from "../internal"; | ||
export declare class Collection<DataType = DefaultItem> { | ||
@@ -159,2 +159,15 @@ agileInstance: () => Agile; | ||
/** | ||
* @public | ||
* Resets this Collection | ||
*/ | ||
reset(): void; | ||
/** | ||
* @public | ||
* Puts ItemKey/s into Group/s (GroupKey/s) | ||
* @param itemKeys - ItemKey/s that get added to provided Group/s | ||
* @param groupKeys - Group/s to which the ItemKey/s get added | ||
* @param config - Config | ||
*/ | ||
put(itemKeys: ItemKey | Array<ItemKey>, groupKeys: GroupKey | Array<GroupKey>, config?: GroupAddConfig): void; | ||
/** | ||
* @internal | ||
@@ -161,0 +174,0 @@ * Updates ItemKey of Item |
@@ -453,2 +453,49 @@ "use strict"; | ||
//========================================================================================================= | ||
// Reset | ||
//========================================================================================================= | ||
/** | ||
* @public | ||
* Resets this Collection | ||
*/ | ||
reset() { | ||
var _a, _b; | ||
// Remove Items from Storage | ||
for (let key in this.data) { | ||
const item = this.getItemById(key); | ||
(_a = item === null || item === void 0 ? void 0 : item.persistent) === null || _a === void 0 ? void 0 : _a.removeValue(); | ||
} | ||
// Reset Groups | ||
for (let key in this.groups) | ||
(_b = this.getGroup(key)) === null || _b === void 0 ? void 0 : _b.reset(); | ||
// Reset Data | ||
this.data = {}; | ||
this.size = 0; | ||
// Reselect Items | ||
for (let key in this.selectors) { | ||
const selector = this.getSelector(key); | ||
selector === null || selector === void 0 ? void 0 : selector.select(selector === null || selector === void 0 ? void 0 : selector.itemKey, { force: true }); | ||
} | ||
} | ||
//========================================================================================================= | ||
// Put | ||
//========================================================================================================= | ||
/** | ||
* @public | ||
* Puts ItemKey/s into Group/s (GroupKey/s) | ||
* @param itemKeys - ItemKey/s that get added to provided Group/s | ||
* @param groupKeys - Group/s to which the ItemKey/s get added | ||
* @param config - Config | ||
*/ | ||
put(itemKeys, groupKeys, config = {}) { | ||
const _itemKeys = internal_1.normalizeArray(itemKeys); | ||
const _groupKeys = internal_1.normalizeArray(groupKeys); | ||
// Add ItemKeys to Groups | ||
_groupKeys.forEach((groupKey) => { | ||
const group = this.getGroup(groupKey); | ||
_itemKeys.forEach((itemKey) => { | ||
group === null || group === void 0 ? void 0 : group.add(itemKey, config); | ||
}); | ||
}); | ||
} | ||
//========================================================================================================= | ||
// Update Item Key | ||
@@ -544,3 +591,2 @@ //========================================================================================================= | ||
} | ||
// TODO | ||
// Remove Selectors that represents this Item | ||
@@ -547,0 +593,0 @@ for (let selectorKey in this.selectors) { |
@@ -48,2 +48,3 @@ import { Collection, DefaultItem, Item, ItemKey, State } from "../internal"; | ||
* @param sideEffects - If Side Effects of Selector get executed | ||
* @param force - Force to select ItemKey | ||
*/ | ||
@@ -53,2 +54,3 @@ export interface SelectConfigInterface { | ||
sideEffects?: boolean; | ||
force?: boolean; | ||
} |
@@ -48,3 +48,8 @@ "use strict"; | ||
sideEffects: true, | ||
force: false, | ||
}); | ||
if ((oldItem === null || oldItem === void 0 ? void 0 : oldItem.key) === itemKey && !config.force) { | ||
console.warn(`Agile: Selector has already selected key '${itemKey}'!`); | ||
return this; | ||
} | ||
// Remove old Item from Collection if it is an Placeholder | ||
@@ -51,0 +56,0 @@ if (oldItem === null || oldItem === void 0 ? void 0 : oldItem.isPlaceholder) |
@@ -53,4 +53,2 @@ "use strict"; | ||
this.perform(performJob); | ||
else | ||
console.warn("Agile: No Job in queue!"); | ||
} | ||
@@ -82,10 +80,10 @@ } | ||
this.perform(performJob); | ||
else | ||
console.warn("Agile: No Job in queue!"); | ||
} | ||
else { | ||
// https://stackoverflow.com/questions/9083594/call-settimeout-without-delay | ||
setTimeout(() => { | ||
this.updateSubscribers(); | ||
}); | ||
if (this.jobsToRerender.length > 0) { | ||
// https://stackoverflow.com/questions/9083594/call-settimeout-without-delay | ||
setTimeout(() => { | ||
this.updateSubscribers(); | ||
}); | ||
} | ||
} | ||
@@ -105,2 +103,4 @@ } | ||
} | ||
if (this.jobsToRerender.length <= 0) | ||
return; | ||
// Subscriptions that has to be updated/rerendered (Set = For preventing double subscriptions without further checks) | ||
@@ -107,0 +107,0 @@ const subscriptionsToUpdate = new Set(); |
@@ -119,2 +119,8 @@ import { Agile, StorageKey, StateObserver, StatePersistent, Observer, StateJobConfigInterface, StatePersistentConfigInterface } from "../internal"; | ||
* @public | ||
* Creates a Watcher that gets once called when the State Value changes for the first time and than destroys itself | ||
* @param callback - Callback Function that gets called if the State Value changes | ||
*/ | ||
onInaugurated(callback: Callback<ValueType>): void; | ||
/** | ||
* @public | ||
* Checks if watcher at given Key exists | ||
@@ -121,0 +127,0 @@ * @param key - Key of Watcher |
@@ -234,2 +234,14 @@ "use strict"; | ||
} | ||
/** | ||
* @public | ||
* Creates a Watcher that gets once called when the State Value changes for the first time and than destroys itself | ||
* @param callback - Callback Function that gets called if the State Value changes | ||
*/ | ||
onInaugurated(callback) { | ||
const watcherKey = "InauguratedWatcher"; | ||
this.watch(watcherKey, () => { | ||
callback(this.getPublicValue()); | ||
this.removeWatcher(watcherKey); | ||
}); | ||
} | ||
//========================================================================================================= | ||
@@ -236,0 +248,0 @@ // Has Watcher |
{ | ||
"name": "@agile-ts/core", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"author": "BennoDev", | ||
@@ -5,0 +5,0 @@ "license": "ISC", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
215353
5307
0