@agile-ts/core
Advanced tools
Comparing version 0.0.12 to 0.0.13
# Change Log | ||
## 0.0.13 | ||
### Patch Changes | ||
- 7f29a97: fixed bugs and increased versions | ||
## 0.0.12 | ||
@@ -4,0 +10,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { Runtime, Integration, State, Storage, Collection, CollectionConfig, DefaultItem, Computed, Event, CreateEventConfigInterface, DefaultEventPayload, Integrations, Observer, SubController, Storages, CreateStorageConfigInterface, RegisterConfigInterface, Logger, CreateLoggerConfigInterface, StateConfigInterface, Group } from './internal'; | ||
import { Runtime, Integration, State, Storage, Collection, CollectionConfig, DefaultItem, Computed, Integrations, Observer, SubController, Storages, CreateStorageConfigInterface, RegisterConfigInterface, Logger, CreateLoggerConfigInterface, StateConfigInterface, Group } from './internal'; | ||
export declare class Agile { | ||
@@ -52,8 +52,2 @@ config: AgileConfigInterface; | ||
* @public | ||
* Event - Class that holds a List of Functions which can be triggered at the same time | ||
* @param config - Config | ||
*/ | ||
createEvent<PayloadType = DefaultEventPayload>(config?: CreateEventConfigInterface): Event<PayloadType>; | ||
/** | ||
* @public | ||
* Integrates framework into Agile | ||
@@ -60,0 +54,0 @@ * @param integration - Integration that gets registered/integrated |
@@ -57,5 +57,2 @@ "use strict"; | ||
} | ||
createEvent(config) { | ||
return new internal_1.Event(this, config); | ||
} | ||
integrate(integration) { | ||
@@ -62,0 +59,0 @@ this.integrations.integrate(integration); |
@@ -53,3 +53,3 @@ import { State, Collection, DefaultItem, ItemKey, Item, StatePersistentConfigInterface, PersistentKey, StateRuntimeJobConfigInterface } from '../internal'; | ||
*/ | ||
remove(itemKeys: ItemKey | ItemKey[], config?: GroupRemoveConfig): this; | ||
remove(itemKeys: ItemKey | ItemKey[], config?: GroupRemoveConfigInterface): this; | ||
/** | ||
@@ -61,3 +61,3 @@ * @public | ||
*/ | ||
add(itemKeys: ItemKey | ItemKey[], config?: GroupAddConfig): this; | ||
add(itemKeys: ItemKey | ItemKey[], config?: GroupAddConfigInterface): this; | ||
/** | ||
@@ -88,3 +88,3 @@ * @public | ||
*/ | ||
rebuild(): void; | ||
rebuild(): this; | ||
} | ||
@@ -97,3 +97,3 @@ export declare type GroupKey = string | number; | ||
*/ | ||
export interface GroupAddConfig { | ||
export interface GroupAddConfigInterface { | ||
method?: 'unshift' | 'push'; | ||
@@ -106,3 +106,3 @@ overwrite?: boolean; | ||
*/ | ||
export interface GroupRemoveConfig { | ||
export interface GroupRemoveConfigInterface { | ||
background?: boolean; | ||
@@ -109,0 +109,0 @@ } |
@@ -144,2 +144,3 @@ "use strict"; | ||
this.notFoundItemKeys = notFoundItemKeys; | ||
return this; | ||
} | ||
@@ -146,0 +147,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { Agile, Item, Group, GroupKey, Selector, SelectorKey, StorageKey, GroupConfigInterface, CollectionPersistent, GroupAddConfig, SideEffectConfigInterface, SelectorConfigInterface } from '../internal'; | ||
import { Agile, Item, Group, GroupKey, Selector, SelectorKey, StorageKey, GroupConfigInterface, CollectionPersistent, GroupAddConfigInterface, SideEffectConfigInterface, SelectorConfigInterface } from '../internal'; | ||
export declare class Collection<DataType = DefaultItem> { | ||
@@ -129,2 +129,8 @@ agileInstance: () => Agile; | ||
* @public | ||
* Creates new Selector that represents an Item of the Collection | ||
* @param itemKey - Key of Item which the Selector represents | ||
*/ | ||
select(itemKey: ItemKey): Selector<DataType>; | ||
/** | ||
* @public | ||
* Check if Selector exists in Collection | ||
@@ -227,3 +233,3 @@ * @param selectorKey - Key/Name of Selector | ||
*/ | ||
reset(): void; | ||
reset(): this; | ||
/** | ||
@@ -236,3 +242,3 @@ * @public | ||
*/ | ||
put(itemKeys: ItemKey | Array<ItemKey>, groupKeys: GroupKey | Array<GroupKey>, config?: GroupAddConfig): void; | ||
put(itemKeys: ItemKey | Array<ItemKey>, groupKeys: GroupKey | Array<GroupKey>, config?: GroupAddConfigInterface): this; | ||
/** | ||
@@ -258,4 +264,4 @@ * @internal | ||
remove(itemKeys: ItemKey | Array<ItemKey>): { | ||
fromGroups: (groups: Array<ItemKey> | ItemKey) => void; | ||
everywhere: () => void; | ||
fromGroups: (groups: Array<ItemKey> | ItemKey) => Collection<DataType>; | ||
everywhere: () => Collection<DataType>; | ||
}; | ||
@@ -268,3 +274,3 @@ /** | ||
*/ | ||
removeFromGroups(itemKeys: ItemKey | Array<ItemKey>, groupKeys: GroupKey | Array<GroupKey>): void; | ||
removeFromGroups(itemKeys: ItemKey | Array<ItemKey>, groupKeys: GroupKey | Array<GroupKey>): this; | ||
/** | ||
@@ -275,3 +281,3 @@ * @public | ||
*/ | ||
removeItems(itemKeys: ItemKey | Array<ItemKey>): void; | ||
removeItems(itemKeys: ItemKey | Array<ItemKey>): this; | ||
/** | ||
@@ -340,7 +346,9 @@ * @internal | ||
/** | ||
* @param addNewProperties - If properties that doesn't exist in base ItemData get added | ||
* @param patch - If Data gets merged into the current Data | ||
* @param background - If updating an Item happens in the background (-> not causing any rerender) | ||
*/ | ||
export interface UpdateConfigInterface { | ||
addNewProperties?: boolean; | ||
patch?: boolean | { | ||
addNewProperties?: boolean; | ||
}; | ||
background?: boolean; | ||
@@ -347,0 +355,0 @@ } |
@@ -51,3 +51,3 @@ "use strict"; | ||
} | ||
Group(initialItems, config) { | ||
Group(initialItems, config = {}) { | ||
if (this.isInstantiated) { | ||
@@ -62,3 +62,3 @@ const key = (config === null || config === void 0 ? void 0 : config.key) || internal_1.generateId(); | ||
} | ||
Selector(initialKey, config) { | ||
Selector(initialKey, config = {}) { | ||
if (this.isInstantiated) { | ||
@@ -152,3 +152,3 @@ const key = (config === null || config === void 0 ? void 0 : config.key) || internal_1.generateId(); | ||
config = internal_1.defineConfig(config, { | ||
addNewProperties: true, | ||
patch: true, | ||
background: false, | ||
@@ -167,4 +167,2 @@ }); | ||
const updateItemKey = oldItemKey !== newItemKey; | ||
if (changes[primaryKey]) | ||
delete changes[primaryKey]; | ||
if (updateItemKey) | ||
@@ -174,6 +172,23 @@ this.updateItemKey(oldItemKey, newItemKey, { | ||
}); | ||
item.patch(changes, { | ||
background: config.background, | ||
addNewProperties: config.addNewProperties, | ||
}); | ||
if (config.patch) { | ||
if (changes[primaryKey]) | ||
delete changes[primaryKey]; | ||
let patchConfig = typeof config.patch === 'object' ? config.patch : {}; | ||
patchConfig = internal_1.defineConfig(patchConfig, { | ||
addNewProperties: true, | ||
}); | ||
item.patch(changes, { | ||
background: config.background, | ||
addNewProperties: patchConfig.addNewProperties, | ||
}); | ||
} | ||
if (!config.patch) { | ||
if (changes[this.config.primaryKey] !== itemKey) { | ||
changes[this.config.primaryKey] = itemKey; | ||
internal_1.Agile.logger.warn(`By overwriting the whole Item don't forget passing the correct primaryKey!`, changes); | ||
} | ||
item.set(changes, { | ||
background: config.background, | ||
}); | ||
} | ||
return item; | ||
@@ -250,2 +265,5 @@ } | ||
} | ||
select(itemKey) { | ||
return this.createSelector(itemKey, itemKey); | ||
} | ||
hasSelector(selectorKey, config = {}) { | ||
@@ -391,2 +409,3 @@ return !!this.getSelector(selectorKey, config); | ||
(_b = this.getSelector(key)) === null || _b === void 0 ? void 0 : _b.reset(); | ||
return this; | ||
} | ||
@@ -400,2 +419,3 @@ put(itemKeys, groupKeys, config = {}) { | ||
}); | ||
return this; | ||
} | ||
@@ -474,2 +494,3 @@ updateItemKey(oldItemKey, newItemKey, config = {}) { | ||
}); | ||
return this; | ||
} | ||
@@ -497,2 +518,3 @@ removeItems(itemKeys) { | ||
}); | ||
return this; | ||
} | ||
@@ -499,0 +521,0 @@ setData(data, config = {}) { |
@@ -1,2 +0,2 @@ | ||
import { State, Agile, Observer, Event, StateConfigInterface, Group, SideEffectConfigInterface } from '../internal'; | ||
import { State, Agile, Observer, StateConfigInterface, Group, SideEffectConfigInterface } from '../internal'; | ||
export declare class Computed<ComputedValueType = any> extends State<ComputedValueType> { | ||
@@ -31,5 +31,5 @@ agileInstance: () => Agile; | ||
* @internal | ||
* Computes Value and adds missing Dependencies to Computed | ||
* Recomputes value and adds missing dependencies to Computed | ||
*/ | ||
computeValue(): ComputedValueType; | ||
compute(): ComputedValueType; | ||
/** | ||
@@ -49,3 +49,3 @@ * @internal | ||
export interface ComputedConfigInterface extends StateConfigInterface { | ||
computedDeps?: Array<Observer | State | Event | Group>; | ||
computedDeps?: Array<Observer | State | Group>; | ||
} | ||
@@ -52,0 +52,0 @@ /** |
@@ -53,3 +53,3 @@ "use strict"; | ||
} | ||
computeValue() { | ||
compute() { | ||
internal_1.ComputedTracker.track(); | ||
@@ -56,0 +56,0 @@ const computedValue = this.computeFunction(); |
@@ -25,6 +25,3 @@ export * from './logger'; | ||
export * from './collection/collection.persistent'; | ||
export * from './event'; | ||
export * from './event/event.job'; | ||
export * from './event/event.observer'; | ||
export * from './integrations'; | ||
export * from './integrations/integration'; |
@@ -37,6 +37,3 @@ "use strict"; | ||
__exportStar(require("./collection/collection.persistent"), exports); | ||
__exportStar(require("./event"), exports); | ||
__exportStar(require("./event/event.job"), exports); | ||
__exportStar(require("./event/event.observer"), exports); | ||
__exportStar(require("./integrations"), exports); | ||
__exportStar(require("./integrations/integration"), exports); |
@@ -16,3 +16,4 @@ import { Agile, StorageKey, StateObserver, StatePersistent, Observer, PersistentKey, StateIngestConfigInterface } from '../internal'; | ||
}; | ||
computeMethod?: ComputeMethod<ValueType>; | ||
computeValueMethod?: ComputeValueMethod<ValueType>; | ||
computeExistsMethod: ComputeExistsMethod<ValueType>; | ||
isPersisted: boolean; | ||
@@ -161,2 +162,8 @@ persistent: StatePersistent | undefined; | ||
* @public | ||
* Function that computes the exists status of the State | ||
* @param method - Computed Function | ||
*/ | ||
computeExists(method: ComputeExistsMethod<ValueType>): this; | ||
/** | ||
* @public | ||
* Equivalent to === | ||
@@ -183,3 +190,3 @@ * @param value - Value that gets checked if its equals to the State Value | ||
*/ | ||
compute(method: ComputeMethod<ValueType>): this; | ||
computeValue(method: ComputeValueMethod<ValueType>): this; | ||
/** | ||
@@ -249,3 +256,4 @@ * @internal | ||
export declare type StateWatcherCallback<T = any> = (value: T, key: string) => void; | ||
export declare type ComputeMethod<T = any> = (value: T) => T; | ||
export declare type ComputeValueMethod<T = any> = (value: T) => T; | ||
export declare type ComputeExistsMethod<T = any> = (value: T) => boolean; | ||
export declare type SideEffectFunctionType<Instance extends State<any>> = (instance: Instance, properties?: { | ||
@@ -252,0 +260,0 @@ [key: string]: any; |
@@ -27,2 +27,5 @@ "use strict"; | ||
this.isPlaceholder = true; | ||
this.computeExistsMethod = (v) => { | ||
return v != null; | ||
}; | ||
if (!config.isPlaceholder) | ||
@@ -204,4 +207,12 @@ this.set(initialValue, { overwrite: true }); | ||
get exists() { | ||
return !this.isPlaceholder; | ||
return !this.isPlaceholder && this.computeExistsMethod(this.value); | ||
} | ||
computeExists(method) { | ||
if (!internal_1.isFunction(method)) { | ||
internal_1.Agile.logger.error(`A 'computeExistsMethod' has to be a function!`); | ||
return this; | ||
} | ||
this.computeExistsMethod = method; | ||
return this; | ||
} | ||
is(value) { | ||
@@ -222,8 +233,9 @@ return internal_1.equal(value, this.value); | ||
} | ||
compute(method) { | ||
computeValue(method) { | ||
if (!internal_1.isFunction(method)) { | ||
internal_1.Agile.logger.error('A computeMethod has to be a function!'); | ||
internal_1.Agile.logger.error(`A 'computeValueMethod' has to be a function!`); | ||
return this; | ||
} | ||
this.computeMethod = method; | ||
this.computeValueMethod = method; | ||
this.set(method(this.nextStateValue)); | ||
return this; | ||
@@ -230,0 +242,0 @@ } |
@@ -15,3 +15,3 @@ "use strict"; | ||
if (state instanceof internal_1.Computed) | ||
newStateValue = state.computeValue(); | ||
newStateValue = state.compute(); | ||
else | ||
@@ -38,4 +38,4 @@ newStateValue = state.nextStateValue; | ||
} | ||
this.nextStateValue = state.computeMethod | ||
? internal_1.copy(state.computeMethod(newStateValue)) | ||
this.nextStateValue = state.computeValueMethod | ||
? internal_1.copy(state.computeValueMethod(newStateValue)) | ||
: internal_1.copy(newStateValue); | ||
@@ -42,0 +42,0 @@ if (internal_1.equal(state._value, this.nextStateValue) && !config.force) |
{ | ||
"name": "@agile-ts/core", | ||
"version": "0.0.12", | ||
"version": "0.0.13", | ||
"author": "BennoDev", | ||
@@ -21,5 +21,5 @@ "license": "MIT", | ||
"prepare": "tsc && tsc -p ./tsconfig.production.json", | ||
"dev-publish": "yalc publish", | ||
"dev-push": "yalc push", | ||
"watch": "tsc-watch --onSuccess \"yarn run dev-push\"", | ||
"dev:publish": "yalc publish", | ||
"dev:push": "yalc push", | ||
"watch": "tsc-watch --onSuccess \"yarn run dev:push\"", | ||
"release": "node ./scripts/prepublish.js && yarn run prepare", | ||
@@ -26,0 +26,0 @@ "preview": "npm pack" |
<img src="https://raw.githubusercontent.com/agile-ts/agile/master/static/header_background.png" alt="AgileTs"> | ||
> **Spacy, Simple, Scalable State Management Framework** | ||
> Global, simple, spacy State and Logic Framework | ||
@@ -32,3 +32,3 @@ <br /> | ||
<p align="left"> | ||
<a href="https://twitter.com/intent/tweet?text=I%20just%20discovered%20AgileTs%3B%20an%20awesome%2C%20spacy%20and%20overall%20easy%20to%20use%20State%20Manager.%0A%60%60%60ts%0Aconst%20MY_STATE%20%3D%20App.createState(%22Hello%20stranger%22)%3B%0AMY_STATE.set(%22Hello%20friend%22)%3B%0A%60%60%60%0Ahttps%3A%2F%2Fgithub.com%2Fagile-ts%2Fagile%2F"><img src="http://randojs.com/images/tweetShield.svg" alt="Tweet" height="20"/> | ||
<a href="https://twitter.com/intent/tweet?text=I%20just%20discovered%20AgileTs%3B%20a%20global%2C%20spacy%20and%20overall%20easy%20to%20use%20State%20Manager.%0A%60%60%60ts%0Aconst%20MY_STATE%20%3D%20App.createState(%22Hello%20stranger%22)%3B%0AMY_STATE.set(%22Hello%20friend%22)%3B%0A%60%60%60%0Ahttps%3A%2F%2Fgithub.com%2Fagile-ts%2Fagile%2F%20%0A%0A%40AgileFramework%20%0A%23agilets%20%23statemanagement%20%23webdev%20"><img src="http://randojs.com/images/tweetShield.svg" alt="Tweet" height="20"/> | ||
</a> | ||
@@ -59,3 +59,3 @@ <a href="https://discord.gg/T9GzreAwPH"> | ||
``` | ||
To find out more checkout our [documentation](https://agile-ts.org/docs/installation). | ||
To find out more checkout our [documentation](https://agile-ts.org/docs/introduction). | ||
@@ -68,3 +68,5 @@ ### β³οΈ Sandbox | ||
More examples can be found in the [Example Section](https://agile-ts.org/docs/examples). | ||
<br /> | ||
@@ -76,42 +78,37 @@ | ||
AgileTs is a global, simple, well-tested State Management Framework implemented in TypeScript. | ||
It's more flexible and boilerplate-free than frameworks like Redux and has a powerful approach to reducing the codebase size through a | ||
centralized memory design pattern. The philosophy behind AgileTs is simple: | ||
### π Straightforward | ||
Write minimalistic, boilerplate free code that captures your intent. | ||
Write minimalistic, boilerplate free code that captures your intent. | ||
**Some straightforward syntax examples:** | ||
- Store State in the Local Storage | ||
- Store State in any Storage, like [Local Storage](https://www.w3schools.com/html/html5_webstorage.asp) | ||
```ts | ||
MY_STATE.persist("storage-key") | ||
``` | ||
- Create reactive Collection of States | ||
- Create a reactive Array of States | ||
```ts | ||
const MY_COLLECTION = App.Collection(); | ||
const MY_COLLECTION = App.createCollection(); | ||
MY_COLLECTION.collect({id: 1, name: "Frank"}); | ||
MY_COLLECTION.collect({id: 2, name: "Dieter"}); | ||
``` | ||
- Mutate or Check States with simple Functions | ||
- Mutate and Check States with simple Functions | ||
```ts | ||
MY_STATE.undo(); // Undo last change | ||
MY_STATE.is({hello: "jeff"}); // Check if State has the Value {hello: "jeff"} | ||
MY_STATE.undo(); // Undo latest change | ||
MY_STATE.is({hello: "jeff"}); // Check if State has the Value '{hello: "jeff"}' | ||
``` | ||
### π€Έβ Flexible | ||
- Works in nearly every UI-Framework. Check [here](https://agile-ts.org/docs/installation) if your desired framework is supported, too. | ||
- Surly behaves with the workflow that suits you best. | ||
No need for _reducers_, _actions_, .. | ||
- Has **no** external dependencies | ||
- Works in nearly any UI-Layer. Check [here](https://agile-ts.org/docs/frameworks) if your preferred Framework is supported too. | ||
- Surly behaves with the workflow which suits you best. No need boilerplate code. | ||
- Has **0** external dependencies | ||
### π Centralize | ||
Manage your Application Logic in a central place outside any UI-Framework. | ||
This makes your code more decoupled, portable, and above all, easily testable. | ||
### π― Easy to Use | ||
Learn the powerful tools of AgileTs in a short amount of time. | ||
A good place to start is in our [documentation](https://agile-ts.org/docs). | ||
And I'm sure you'll be able to use AgileTs very soon. | ||
A good place to start are our [Quick Start Guides](https://agile-ts.org/docs/installation) | ||
or if you are no fan of following any tutorial, checkout your [Examples](https://agile-ts.org/docs/examples). | ||
### π Lightweight | ||
AgileTs has an unpacked size of [52.7kB](https://bundlephobia.com/result?p=@agile-ts/core@0.0.6) | ||
and [0 dependencies](https://www.npmjs.com/package/@agile-ts/core). | ||
<br /> | ||
@@ -123,3 +120,3 @@ | ||
To properly use AgileTs, in an UI-Framework we need **two** packages. | ||
To properly use AgileTs, in a UI-Framework we need to install **two** packages. | ||
@@ -131,4 +128,4 @@ - The _Core Package_, which acts as the brain of AgileTs and manages all our States | ||
- And a _fitting Integration_ for our preferd UI-Framework.. in my case [React](https://www.npmjs.com/package/@agile-ts/react). | ||
Check [here](https://agile-ts.org/docs/installation) if your desired Framework is supported, too. | ||
- and a _fitting Integration_ for our preferd UI-Framework. In my case the [React Integration](https://www.npmjs.com/package/@agile-ts/react). | ||
Check [here](https://agile-ts.org/docs/frameworks) if your desired Framework is supported, too. | ||
``` | ||
@@ -145,6 +142,6 @@ npm install @agile-ts/react | ||
If AgileTs sounds interesting to you. | ||
Checkout our **[docs](https://agile-ts.org/docs/)**. | ||
And I am sure you will be able to use it in no time. | ||
In case you have any questions don't mind joining our [Discord Community](https://discord.gg/FTqeMNCxw7). | ||
Sounds AgileTs interesting to you? | ||
Checkout our **[documentation](https://agile-ts.org/docs/introduction)**, to learn more. | ||
And I promise you, you will be able to use AgileTs in no time. | ||
In case you have any further questions don't mind joining our [Community Discord](https://discord.gg/T9GzreAwPH). | ||
@@ -158,5 +155,4 @@ | ||
Get a part of AgileTs and start contributing. | ||
Get a part of AgileTs and start contributing. We welcome any meaningful contribution π | ||
To find out more checkout the [CONTRIBUTING.md](https://github.com/agile-ts/agile/blob/master/CONTRIBUTING.md). | ||
We welcome any meaningful contribution π | ||
@@ -180,2 +176,3 @@ <a href="https://codeclimate.com/github/agile-ts/agile/coverage.svg"> | ||
| [@agile-ts/multieditor](/packages/multieditor) | [![badge](https://img.shields.io/npm/v/@agile-ts/multieditor.svg?style=flat-square)](https://www.npmjs.com/package/@agile-ts/multieditor) | Simple Form Manager | | ||
| [@agile-ts/event](/packages/event) | [![badge](https://img.shields.io/npm/v/@agile-ts/event.svg?style=flat-square)](https://www.npmjs.com/package/@agile-ts/event) | Handy class for emitting UI Events | | ||
@@ -189,2 +186,3 @@ | ||
AgileTs is inspired by [PulseJs](https://github.com/pulse-framework/pulse) | ||
AgileTs is inspired by [MVVM Frameworks](https://de.wikipedia.org/wiki/Model_View_ViewModel) like [MobX](https://mobx.js.org/README.html) and [PulseJs](https://github.com/pulse-framework/pulse). | ||
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
201430
60
5175
179