Socket
Socket
Sign inDemoInstall

@agile-ts/core

Package Overview
Dependencies
0
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.13 to 0.0.14

10

CHANGELOG.md
# Change Log
## 0.0.14
### Patch Changes
- 63b8760: - extracted fromatDeps
- made globalBind optional
- optimized internal classes
- optimized packages.json for better npm ranking score
- fixed collection type issue
## 0.0.13

@@ -4,0 +14,0 @@

3

dist/agile.d.ts

@@ -10,2 +10,3 @@ import { Runtime, Integration, State, Storage, Collection, CollectionConfig, DefaultItem, Computed, Integrations, Observer, SubController, Storages, CreateStorageConfigInterface, RegisterConfigInterface, Logger, CreateLoggerConfigInterface, StateConfigInterface, Group } from './internal';

static logger: Logger;
static globalKey: string;
/**

@@ -79,2 +80,3 @@ * @public

* @param storageConfig - To configure Agile Storage
* @param bindGlobal - Binds Agile Instance Global
*/

@@ -85,2 +87,3 @@ export interface CreateAgileConfigInterface {

localStorage?: boolean;
bindGlobal?: boolean;
}

@@ -87,0 +90,0 @@ /**

8

dist/agile.js

@@ -11,2 +11,3 @@ "use strict";

logConfig: {},
bindGlobal: false,
});

@@ -31,4 +32,6 @@ config.logConfig = internal_1.defineConfig(config.logConfig, {

Agile.logger.success('Created new AgileInstance ', this, Agile.logger);
if (!internal_1.globalBind('__agile__', this))
Agile.logger.warn('Be careful with multiple Agile Instances in one Application!');
if (config.bindGlobal) {
if (!internal_1.globalBind(Agile.globalKey, this))
Agile.logger.warn('Be careful with binding multiple Agile Instances global in one Application!');
}
}

@@ -81,1 +84,2 @@ createStorage(config) {

});
Agile.globalKey = '__agile__';

@@ -1,2 +0,2 @@

import { State, Collection, DefaultItem, ItemKey, Item, StatePersistentConfigInterface, PersistentKey, StateRuntimeJobConfigInterface } from '../internal';
import { State, Collection, DefaultItem, ItemKey, Item, StatePersistentConfigInterface, PersistentKey, StateRuntimeJobConfigInterface, StateIngestConfigInterface } from '../internal';
export declare class Group<DataType = DefaultItem> extends State<Array<ItemKey>> {

@@ -53,3 +53,3 @@ static rebuildGroupSideEffectKey: string;

*/
remove(itemKeys: ItemKey | ItemKey[], config?: GroupRemoveConfigInterface): this;
remove(itemKeys: ItemKey | ItemKey[], config?: StateIngestConfigInterface): this;
/**

@@ -95,6 +95,5 @@ * @public

*/
export interface GroupAddConfigInterface {
export interface GroupAddConfigInterface extends StateIngestConfigInterface {
method?: 'unshift' | 'push';
overwrite?: boolean;
background?: boolean;
}

@@ -101,0 +100,0 @@ /**

@@ -40,5 +40,2 @@ "use strict";

let newGroupValue = internal_1.copy(this.nextStateValue);
config = internal_1.defineConfig(config, {
background: false,
});
_itemKeys.forEach((itemKey) => {

@@ -59,3 +56,3 @@ if (!newGroupValue.includes(itemKey)) {

config.background = true;
this.set(newGroupValue, { background: config.background });
this.set(newGroupValue, config);
return this;

@@ -71,3 +68,2 @@ }

overwrite: false,
background: false,
});

@@ -94,3 +90,3 @@ _itemKeys.forEach((itemKey) => {

config.background = true;
this.set(newGroupValue, { background: config.background });
this.set(newGroupValue, internal_1.removeProperties(config, ['method', 'overwrite']));
return this;

@@ -97,0 +93,0 @@ }

@@ -14,6 +14,6 @@ import { Agile, Item, Group, GroupKey, Selector, SelectorKey, StorageKey, GroupConfigInterface, CollectionPersistent, GroupAddConfigInterface, SideEffectConfigInterface, SelectorConfigInterface } from '../internal';

groups: {
[key: string]: Group<any>;
[key: string]: Group<DataType>;
};
selectors: {
[key: string]: Selector<any>;
[key: string]: Selector<DataType>;
};

@@ -293,5 +293,3 @@ isInstantiated: boolean;

}
export declare type DefaultItem = {
[key: string]: any;
};
export declare type DefaultItem = Record<string, any>;
export declare type CollectionKey = string | number;

@@ -298,0 +296,0 @@ export declare type ItemKey = string | number;

@@ -42,3 +42,3 @@ import { Collection, DefaultItem, Item, ItemKey, State, StateRuntimeJobConfigInterface } from '../internal';

* Checks if Selector has selected passed ItemKey
* @param itemKey
* @param itemKey - ItemKey
*/

@@ -51,3 +51,3 @@ hasSelected(itemKey: ItemKey): boolean;

*/
rebuildSelector(config?: StateRuntimeJobConfigInterface): void;
rebuildSelector(config?: StateRuntimeJobConfigInterface): this;
}

@@ -54,0 +54,0 @@ export declare type SelectorKey = string | number;

@@ -88,5 +88,6 @@ "use strict";

this.set(undefined, config);
return;
return this;
}
this.set(this.item._value, config);
return this;
}

@@ -93,0 +94,0 @@ }

@@ -1,2 +0,2 @@

import { State, Agile, Observer, StateConfigInterface, Group, SideEffectConfigInterface } from '../internal';
import { State, Agile, Observer, StateConfigInterface, Collection, StateIngestConfigInterface } from '../internal';
export declare class Computed<ComputedValueType = any> extends State<ComputedValueType> {

@@ -20,3 +20,3 @@ agileInstance: () => Agile;

*/
recompute(config?: RecomputeConfigInterface): void;
recompute(config?: RecomputeConfigInterface): this;
/**

@@ -29,3 +29,3 @@ * @public

*/
updateComputeFunction(computeFunction: () => ComputedValueType, deps?: Array<Observer | State | Event>, config?: UpdateComputeFunctionInterface): void;
updateComputeFunction(computeFunction: () => ComputedValueType, deps?: Array<SubscribableAgileInstancesType>, config?: UpdateComputeFunctionConfigInterface): this;
/**

@@ -35,9 +35,3 @@ * @internal

*/
compute(): ComputedValueType;
/**
* @internal
* Gets Observer out of passed Instances
* @param instances - Instances that hold an Observer
*/
formatDeps(instances: Array<any>): Array<Observer>;
compute(config?: ComputeConfigInterface): ComputedValueType;
patch(): this;

@@ -51,11 +45,9 @@ persist(): this;

export interface ComputedConfigInterface extends StateConfigInterface {
computedDeps?: Array<Observer | State | Group>;
computedDeps?: Array<SubscribableAgileInstancesType>;
}
/**
* @param background - If recomputing value happens in the background (-> not causing any rerender)
* @param sideEffects - If Side Effects of Computed get executed
* @param autodetect - If dependencies get autodetected
*/
export interface RecomputeConfigInterface {
background?: boolean;
sideEffects?: SideEffectConfigInterface;
export interface ComputeConfigInterface {
autodetect?: boolean;
}

@@ -65,4 +57,8 @@ /**

*/
export interface UpdateComputeFunctionInterface extends RecomputeConfigInterface {
export interface UpdateComputeFunctionConfigInterface extends RecomputeConfigInterface {
overwriteDeps?: boolean;
}
export interface RecomputeConfigInterface extends StateIngestConfigInterface, ComputeConfigInterface {
}
declare type SubscribableAgileInstancesType = State | Collection | Observer;
export {};

@@ -18,26 +18,19 @@ "use strict";

this.computeFunction = computeFunction;
this.hardCodedDeps = this.formatDeps(config.computedDeps);
this.hardCodedDeps = internal_1.extractObservers(config.computedDeps).filter((dep) => dep !== undefined);
this.deps = this.hardCodedDeps;
this.recompute();
this.recompute({ autodetect: true });
}
recompute(config = {}) {
config = internal_1.defineConfig(config, {
background: false,
sideEffects: {
enabled: true,
exclude: [],
},
autodetect: false,
});
this.ingest(config);
this.observer.ingestValue(this.compute({ autodetect: config.autodetect }), internal_1.removeProperties(config, ['autodetect']));
return this;
}
updateComputeFunction(computeFunction, deps = [], config = {}) {
config = internal_1.defineConfig(config, {
background: false,
sideEffects: {
enabled: true,
exclude: [],
},
overwriteDeps: true,
autodetect: true,
});
const newDeps = this.formatDeps(deps);
const newDeps = internal_1.extractObservers(deps).filter((dep) => dep !== undefined);
if (config.overwriteDeps)

@@ -49,33 +42,23 @@ this.hardCodedDeps = newDeps;

this.computeFunction = computeFunction;
this.recompute({
background: config.background,
sideEffects: config.sideEffects,
this.recompute(internal_1.removeProperties(config, ['overwriteDeps']));
return this;
}
compute(config = {}) {
config = internal_1.defineConfig(config, {
autodetect: true,
});
}
compute() {
internal_1.ComputedTracker.track();
if (config.autodetect)
internal_1.ComputedTracker.track();
const computedValue = this.computeFunction();
const foundDeps = internal_1.ComputedTracker.getTrackedObservers();
const newDeps = [];
this.hardCodedDeps.concat(foundDeps).forEach((observer) => {
newDeps.push(observer);
observer.depend(this.observer);
});
this.deps = newDeps;
if (config.autodetect) {
const foundDeps = internal_1.ComputedTracker.getTrackedObservers();
const newDeps = [];
this.hardCodedDeps.concat(foundDeps).forEach((observer) => {
newDeps.push(observer);
observer.depend(this.observer);
});
this.deps = newDeps;
}
return computedValue;
}
formatDeps(instances) {
const finalInstances = [];
for (const instance of instances) {
if (instance instanceof internal_1.Observer) {
finalInstances.push(instance);
continue;
}
if (instance !== undefined &&
instance['observer'] !== undefined &&
instance['observer'] instanceof internal_1.Observer)
finalInstances.push(instance['observer']);
}
return finalInstances;
}
patch() {

@@ -82,0 +65,0 @@ internal_1.Agile.logger.error("You can't use patch method on ComputedState!");

@@ -57,11 +57,3 @@ "use strict";

config = internal_1.defineConfig(config, {
sideEffects: {
enabled: true,
exclude: [],
},
background: false,
force: false,
storage: true,
overwrite: false,
perform: true,
});

@@ -103,10 +95,2 @@ if (!this.hasCorrectType(value)) {

addNewProperties: true,
sideEffects: {
enabled: true,
exclude: [],
},
background: false,
force: false,
storage: true,
overwrite: false,
});

@@ -122,9 +106,3 @@ if (!internal_1.isValidObject(this.nextStateValue)) {

this.nextStateValue = internal_1.flatMerge(internal_1.copy(this.nextStateValue), targetWithChanges, { addNewProperties: config.addNewProperties });
this.ingest({
background: config.background,
force: config.force,
overwrite: config.overwrite,
sideEffects: config.sideEffects,
storage: config.storage,
});
this.ingest(internal_1.removeProperties(config, ['addNewProperties']));
return this;

@@ -131,0 +109,0 @@ }

@@ -1,2 +0,2 @@

import { Agile } from './internal';
import { Agile, Observer } from './internal';
/**

@@ -40,2 +40,8 @@ * @internal

/**
* @private
* Extract Observers from specific Instances
* @param instances - Instances that will be formatted
*/
export declare function extractObservers(instances: any): Array<Observer | undefined>;
/**
* @internal

@@ -54,9 +60,2 @@ * Checks if value is a function

* @internal
* Checks the correctness of an url
* Resource: https://stackoverflow.com/questions/5717093/check-if-a-javascript-string-is-a-url
* @param url - Url that gets tested for its correctness
*/
export declare function isValidUrl(url: string): boolean;
/**
* @internal
* Checks if value is valid JsonString

@@ -129,2 +128,9 @@ * @param value - Value that gets checked

* @internal
* Removes properties from Object
* @param object - Object from which the properties get removed
* @param properties - Properties that get removed from the object
*/
export declare function removeProperties<T = Object>(object: T, properties: Array<string>): T;
/**
* @internal
* Binds passed Instance globally at passed Key

@@ -131,0 +137,0 @@ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.globalBind = exports.clone = exports.createArrayFromObject = exports.generateId = exports.notEqual = exports.equal = exports.flatMerge = exports.defineConfig = exports.isJsonString = exports.isValidUrl = exports.isAsyncFunction = exports.isFunction = exports.getAgileInstance = exports.normalizeArray = exports.includesArray = exports.isValidObject = exports.copy = void 0;
exports.globalBind = exports.removeProperties = exports.clone = exports.createArrayFromObject = exports.generateId = exports.notEqual = exports.equal = exports.flatMerge = exports.defineConfig = exports.isJsonString = exports.isAsyncFunction = exports.isFunction = exports.extractObservers = exports.getAgileInstance = exports.normalizeArray = exports.includesArray = exports.isValidObject = exports.copy = void 0;
const internal_1 = require("./internal");

@@ -60,3 +60,3 @@ function copy(value) {

}
return globalThis['__agile__'];
return globalThis[internal_1.Agile.globalKey];
}

@@ -69,2 +69,29 @@ catch (e) {

exports.getAgileInstance = getAgileInstance;
function extractObservers(instances) {
const instancesArray = [];
const tempInstancesArray = normalizeArray(instances, {
createUndefinedArray: true,
});
for (const instance of tempInstancesArray) {
if (!instance) {
instancesArray.push(undefined);
continue;
}
if (instance instanceof internal_1.Collection) {
instancesArray.push(instance.getGroupWithReference(instance.config.defaultGroupKey).observer);
continue;
}
if (instance['observer'] && instance['observer'] instanceof internal_1.Observer) {
instancesArray.push(instance['observer']);
continue;
}
if (instance instanceof internal_1.Observer) {
instancesArray.push(instance);
continue;
}
instancesArray.push(undefined);
}
return instancesArray;
}
exports.extractObservers = extractObservers;
function isFunction(value) {

@@ -81,12 +108,2 @@ return typeof value === 'function';

exports.isAsyncFunction = isAsyncFunction;
function isValidUrl(url) {
const pattern = new RegExp('^(https?:\\/\\/)?' +
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' +
'((\\d{1,3}\\.){3}\\d{1,3}))' +
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' +
'(\\?[;&a-z\\d%_.~+=-]*)?' +
'(\\#[-a-z\\d_]*)?$', 'i');
return pattern.test(url);
}
exports.isValidUrl = isValidUrl;
function isJsonString(value) {

@@ -172,2 +189,8 @@ if (typeof value !== 'string')

exports.clone = clone;
function removeProperties(object, properties) {
const copiedObject = copy(object);
properties.map((property) => delete copiedObject[property]);
return copiedObject;
}
exports.removeProperties = removeProperties;
function globalBind(key, instance, overwrite = false) {

@@ -179,3 +202,3 @@ try {

}
if (!globalThis[key]) {
if (globalThis[key] == null) {
globalThis[key] = instance;

@@ -182,0 +205,0 @@ return true;

{
"name": "@agile-ts/core",
"version": "0.0.13",
"version": "0.0.14",
"author": "BennoDev",

@@ -9,8 +9,18 @@ "license": "MIT",

"keywords": [
"agile",
"agile-ts",
"state-management",
"state management",
"react",
"vue",
"state",
"management",
"typescript",
"reactive"
"javascript",
"reactive",
"modular",
"simple",
"redux",
"replace redux",
"state-machine",
"functional-reactive-programming",
"agile",
"agile-ts"
],

@@ -26,3 +36,6 @@ "main": "dist/index.js",

"release": "node ./scripts/prepublish.js && yarn run prepare",
"preview": "npm pack"
"preview": "npm pack",
"test": "jest",
"test:coverage": "jest --coverage",
"lint": "eslint src/**/*"
},

@@ -36,7 +49,11 @@ "publishConfig": {

},
"bugs": {
"url": "https://github.com/agile-ts/agile/issues"
},
"files": [
"dist",
"LICENSE",
"README.md"
"README.md",
"CHANGELOG.md"
]
}

@@ -45,7 +45,7 @@ <img src="https://raw.githubusercontent.com/agile-ts/agile/master/static/header_background.png" alt="AgileTs">

// Let's start by creating an Instance of AgileTs
// 1️⃣ Create Instance of AgileTs
const App = new Agile();
// Now we are able to build our first State πŸ˜ƒ
const MY_FIRST_STATE = App.createState("Hello Stranger!");
// 2️⃣ Create State with help of before defined Agile Instance
const MY_FIRST_STATE = App.createState("Hello Friend!");

@@ -55,11 +55,14 @@

// Finally, we bind our just created State to our desired UI-Component
// And wolla its reactive. Everytime the State mutates the Component gets rerendered
const myFirstState = useAgile(MY_FIRST_STATE); // returns value of State ("Hello Stranger!")
// 3️⃣ Bind initialized State to desired UI-Component
// And wolla, it's reactive. Everytime the State mutates the Component rerenders
const myFirstState = useAgile(MY_FIRST_STATE); // Returns value of State ("Hello Friend!")
```
To find out more checkout our [documentation](https://agile-ts.org/docs/introduction).
To learn out more, check out our [Quick Start Guides](https://agile-ts.org/docs/Installation.md).
### ⛳️ Sandbox
Test AgileTs yourself, it's only one click away. Just select your preferred Framework below.
Test AgileTs yourself in a [codesandbox](https://codesandbox.io/s/agilets-first-state-f12cz).
It's only one click away. Just select your preferred Framework below.
- [React](https://codesandbox.io/s/agilets-first-state-f12cz)
- [React-Native](https://snack.expo.io/@bennodev/agilets-first-state)
- Vue (coming soon)

@@ -77,13 +80,21 @@ - Angular (coming soon)

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:
AgileTs is a global, simple, well-tested State Management Framework implemented in Typescript.
It offers a reimagined API that focus on **developer experience** and allows you to **quickly** and **easily** manage your States.
Besides States, AgileTs offers some other powerful apis that make your life easier.
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:**
- Mutate and Check States with simple Functions
```ts
MY_STATE.undo(); // Undo latest change
MY_STATE.is({hello: "jeff"}); // Check if State has the Value '{hello: "jeff"}'
MY_STATE.watch((value) => {console.log(value);}); // Watch on State changes
```
- Store State in any Storage, like [Local Storage](https://www.w3schools.com/html/html5_webstorage.asp)
```ts
MY_STATE.persist("storage-key")
MY_STATE.persist("storage-key");
```

@@ -96,19 +107,27 @@ - Create a reactive Array of States

```
- Mutate and Check States with simple Functions
- Compute State depending on other States
```ts
MY_STATE.undo(); // Undo latest change
MY_STATE.is({hello: "jeff"}); // Check if State has the Value '{hello: "jeff"}'
const MY_INTRODUCTION = App.createComputed(() => {
return `Hello I am '${MY_NAME.vale}' and I use ${MY_STATE_MANAGER.value} for State Management.`;
});
```
### πŸ€Έβ€ Flexible
- 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.
- 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 for _reducers_, _actions_, ..
- Has **0** external dependencies
### ⛳️ Centralize
AgileTs is designed to take all business logic out of UI-Components and put them in a central place often called `core`.
The benefit of keeping logic separate to UI-Components is to make 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 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).
Learn the powerful tools of AgileTs in a short amount of time. An excellent place to start are
our [Quick Start](https://agile-ts.org/docs/Installation) Guides, or if you don't like to follow any tutorials,
you can jump straight into our [Example](https://agile-ts.org/docs/examples/Introduction) Section.
<br />

@@ -122,3 +141,3 @@

- The _Core Package_, which acts as the brain of AgileTs and manages all our States
- The _Core Package_, which acts as the brain of AgileTs and manages all your States
```

@@ -128,3 +147,3 @@ npm install @agile-ts/core

- and a _fitting Integration_ for our preferd UI-Framework. In my case the [React Integration](https://www.npmjs.com/package/@agile-ts/react).
- and a _fitting Integration_ for your 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,3 +164,3 @@ ```

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).
In case you have any further questions don't hesitate joining our [Community Discord](https://discord.gg/T9GzreAwPH).

@@ -171,5 +190,5 @@

| ------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------- |
| [@agile-ts/core](/packages/core) | [![badge](https://img.shields.io/npm/v/@agile-ts/core.svg?style=flat-square)](https://www.npmjs.com/package/@agile-ts/core) | Brain of Agile |
| [@agile-ts/core](/packages/core) | [![badge](https://img.shields.io/npm/v/@agile-ts/core.svg?style=flat-square)](https://www.npmjs.com/package/@agile-ts/core) | State Manager |
| [@agile-ts/react](/packages/react) | [![badge](https://img.shields.io/npm/v/@agile-ts/react.svg?style=flat-square)](https://www.npmjs.com/package/@agile-ts/react) | React Integration |
| [@agile-ts/api](/packages/api) | [![badge](https://img.shields.io/npm/v/@agile-ts/api.svg?style=flat-square)](https://www.npmjs.com/package/@agile-ts/api) | Promise based Api |
| [@agile-ts/api](/packages/api) | [![badge](https://img.shields.io/npm/v/@agile-ts/api.svg?style=flat-square)](https://www.npmjs.com/package/@agile-ts/api) | Promise based API |
| [@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 |

@@ -176,0 +195,0 @@ | [@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 |

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc