From bfd199b82f0018f8f019129cee51bbfeddc9e5f1 Mon Sep 17 00:00:00 2001 From: Benno Kohrs Date: Tue, 8 Sep 2020 20:42:28 +0200 Subject: [PATCH 01/25] Created event.ts --- src/event/event.ts | 181 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 src/event/event.ts diff --git a/src/event/event.ts b/src/event/event.ts new file mode 100644 index 00000000..d1641000 --- /dev/null +++ b/src/event/event.ts @@ -0,0 +1,181 @@ +import Agile from "../agile"; +import {defineConfig} from "../utils"; + +export type EventPayload = { [key: string]: any }; +export type EventCallbackFunction = (payload?: PayloadType) => void; + +export interface EventConfig { + key?: string + enabled?: boolean + maxUses?: number + delay?: number +} + +export class Event { + public agileInstance: () => Agile; + + public config: EventConfig; + + private callbacks: Set> = new Set(); // Stores callback functions + public uses: number = 0; // How often the event has been used + private currentTimeout: any; // The current timeout (function) + private queue: Array = []; // Queue if something is currently in timeout + + constructor(agileInstance: Agile, config: EventConfig = {}) { + this.agileInstance = () => agileInstance; + + // Assign defaults to config + this.config = defineConfig(config, { + enabled: true + }); + } + + + //========================================================================================================= + // On + //========================================================================================================= + /** + * Register Callback Function + */ + public on(callback: EventCallbackFunction) { + const cleanUpFunction = () => this.unsub(callback); + + if (this.config.maxUses && this.uses > this.config.maxUses) { + // Disable Event + this.disable(); + + return cleanUpFunction(); + } + + // Add callback to Event Callbacks + this.callbacks.add(callback); + + return cleanUpFunction(); + } + + + //========================================================================================================= + // Trigger + //========================================================================================================= + /** + * Run all callback Functions + */ + public trigger(payload?: PayloadType) { + // If event is disabled, return + if (!this.config.enabled) return this; + + if (this.config.delay) + this.delayedTrigger(payload); + else + this.normalTrigger(payload); + + return this; + } + + + //========================================================================================================= + // Disable + //========================================================================================================= + /** + * Disables the Event + */ + public disable() { + this.config.enabled = false; + return this; + } + + //========================================================================================================= + // Enable + //========================================================================================================= + /** + * Enables the Event + */ + public enable() { + this.config.enabled = true; + return this; + } + + + //========================================================================================================= + // Reset + //========================================================================================================= + /** + * Resets the Event + */ + public reset() { + // Enable event + this.enable(); + + // Reset Uses + this.uses = 0; + + // Clear active timeout + clearTimeout(this.currentTimeout); + + return this; + } + + //========================================================================================================= + // Unsub + //========================================================================================================= + /** + * @internal + * Unsubs a callback + */ + private unsub(callback: EventCallbackFunction) { + this.callbacks.delete(callback); + } + + + //========================================================================================================= + // Normal Trigger + //========================================================================================================= + /** + * @internal + * Call event instantly + */ + private normalTrigger(payload?: PayloadType) { + // Call callbacks + this.callbacks.forEach(callback => callback(payload)); + + // Increase uses + this.uses++; + } + + + //========================================================================================================= + // Delayed Trigger + //========================================================================================================= + /** + * @internal + * Call event after config.delay + */ + private delayedTrigger(payload?: PayloadType) { + // Check if a timeout is currently active if so add the payload to a queue + if (this.currentTimeout !== undefined) { + if (payload) this.queue.push(payload); + return; + } + + // Looper function which loops through the queue(payloads) + const looper = (payload?: PayloadType) => { + this.currentTimeout = setTimeout(() => { + // Reset currentTimeout + this.currentTimeout = undefined; + + // Call normalTrigger + this.normalTrigger(payload); + + // If items are in queue, continue with them + if (this.queue.length > 0) + looper(this.queue.shift()) + }, this.config.delay); + } + + // Call looper with current Payload + looper(payload); + + return; + } + +} From b20ef911c660050d1a8aec72f86278dd4b90e204 Mon Sep 17 00:00:00 2001 From: Benno Kohrs Date: Tue, 8 Sep 2020 20:59:54 +0200 Subject: [PATCH 02/25] Created useEvent Hook --- src/event/{event.ts => index.ts} | 6 ++++-- src/index.ts | 1 + src/integrations/react.integration.ts | 30 +++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) rename src/event/{event.ts => index.ts} (96%) diff --git a/src/event/event.ts b/src/event/index.ts similarity index 96% rename from src/event/event.ts rename to src/event/index.ts index d1641000..b1968233 100644 --- a/src/event/event.ts +++ b/src/event/index.ts @@ -20,6 +20,8 @@ export class Event { public uses: number = 0; // How often the event has been used private currentTimeout: any; // The current timeout (function) private queue: Array = []; // Queue if something is currently in timeout + // @ts-ignore + public payload: PayloadType; // Only holds reference to the PayloadType so that it can be read external (never defined) constructor(agileInstance: Agile, config: EventConfig = {}) { this.agileInstance = () => agileInstance; @@ -44,13 +46,13 @@ export class Event { // Disable Event this.disable(); - return cleanUpFunction(); + return cleanUpFunction; } // Add callback to Event Callbacks this.callbacks.add(callback); - return cleanUpFunction(); + return cleanUpFunction; } diff --git a/src/index.ts b/src/index.ts index 8d67a75e..9dc38d0f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,5 +5,6 @@ export * from './state'; // Framework based exports export {useAgile} from './integrations/react.integration'; export {AgileHOC} from './integrations/react.integration'; +export {useEvent} from './integrations/react.integration'; export default Agile; diff --git a/src/integrations/react.integration.ts b/src/integrations/react.integration.ts index 99dcdc77..9d9a1381 100644 --- a/src/integrations/react.integration.ts +++ b/src/integrations/react.integration.ts @@ -5,6 +5,7 @@ import {Integration} from "./use"; import {SubscriptionContainer} from "../sub"; import {Collection} from "../collection"; import {Group} from "../collection/group"; +import {Event, EventCallbackFunction} from "../event"; //========================================================================================================= @@ -182,6 +183,35 @@ export function useAgile, Y exte } +//========================================================================================================= +// Use Event Hook +//========================================================================================================= + +export function useEvent(event: E, callback: EventCallbackFunction, agileInstance?: Agile) { + // Get Agile Instance + if (!agileInstance) { + const tempAgileInstance = event.agileInstance(); + if (!tempAgileInstance) { + console.error("Agile: Failed to get Agile Instance"); + return; + } + agileInstance = tempAgileInstance; + } + + // Get React constructor + const React = agileInstance.integration?.frameworkConstructor; + if (!React) { + console.error("Agile: Failed to get Framework Constructor"); + return; + } + + React.useEffect(function () { + // Call event on component mount and remove event on component unmount + return event.on(callback); + }, []); +} + + //========================================================================================================= // Framework Integration //========================================================================================================= From 9297b483b8ed58eb12d2f1e91ee6eb4ab7f5b173 Mon Sep 17 00:00:00 2001 From: Benno Kohrs Date: Tue, 8 Sep 2020 21:11:52 +0200 Subject: [PATCH 03/25] Updated getAgileInstance (utils) --- src/integrations/react.integration.ts | 2 +- src/utils.ts | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/integrations/react.integration.ts b/src/integrations/react.integration.ts index 9d9a1381..8b445d91 100644 --- a/src/integrations/react.integration.ts +++ b/src/integrations/react.integration.ts @@ -190,7 +190,7 @@ export function useAgile, Y exte export function useEvent(event: E, callback: EventCallbackFunction, agileInstance?: Agile) { // Get Agile Instance if (!agileInstance) { - const tempAgileInstance = event.agileInstance(); + const tempAgileInstance = getAgileInstance(event); if (!tempAgileInstance) { console.error("Agile: Failed to get Agile Instance"); return; diff --git a/src/utils.ts b/src/utils.ts index feb47f4c..f36c27de 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,5 +1,7 @@ import {State} from "./state"; import Agile from "./agile"; +import {Event} from "./event"; +import {Collection} from "./collection"; //========================================================================================================= @@ -61,13 +63,19 @@ export function normalizeArray(items?: DataType | Array Date: Wed, 9 Sep 2020 21:11:02 +0200 Subject: [PATCH 04/25] Created default exports --- src/agile.ts | 20 ++++++++++++++----- src/api/{api.ts => index.ts} | 0 src/collection/group.ts | 6 +++--- src/collection/index.ts | 10 +++++----- src/collection/item.ts | 4 ++-- src/collection/perstist.ts | 2 +- src/collection/selector.ts | 6 +++--- src/computed/index.ts | 4 ++-- src/event/index.ts | 3 ++- src/integrations/react.integration.ts | 8 ++++---- src/integrations/test.integration.ts | 6 +++--- src/runtime.ts | 4 ++-- src/state/dep.ts | 2 +- src/state/index.ts | 2 +- src/state/persist.ts | 2 +- src/storage.ts | 4 ++-- src/sub.ts | 2 +- src/utils.ts | 6 +++--- test/collection/default.spec.ts | 4 ++-- .../functions/collect.function.spec.ts | 2 +- .../functions/createGroup.function.spec.ts | 2 +- .../functions/createSelector.function.spec.ts | 2 +- .../functions/findById.function.spec.ts | 3 ++- .../functions/getGroup.function.spec.ts | 2 +- .../functions/getSelector.function.spec.ts | 2 +- .../functions/getValueById.function.spec.ts | 2 +- .../functions/update.function.spec.ts | 2 +- test/collection/group/default.spec.ts | 2 +- .../group/functions/add.function.spec.ts | 2 +- .../group/functions/has.function.spec.ts | 2 +- .../group/functions/remove.function.spec.ts | 2 +- test/collection/selector/default.spec.ts | 2 +- .../functions/select.function.spec.ts | 2 +- test/computed/default.ts | 2 +- .../updateComputeFunction.function.spec.ts | 2 +- 35 files changed, 70 insertions(+), 58 deletions(-) rename src/api/{api.ts => index.ts} (100%) diff --git a/src/agile.ts b/src/agile.ts index 79b4dcca..7421b8ca 100644 --- a/src/agile.ts +++ b/src/agile.ts @@ -1,11 +1,12 @@ import Runtime from "./runtime"; import use, {Integration} from "./integrations/use"; import SubController from "./sub"; -import {State} from "./state"; +import State from "./state"; import Storage, {StorageConfigInterface} from "./storage"; -import {Collection, Config, DefaultDataItem} from "./collection"; -import {Computed} from "./computed"; -import API, {apiConfig} from "./api/api"; +import Collection, {Config, DefaultDataItem} from "./collection"; +import Computed from "./computed"; +import API, {apiConfig} from "./api"; +import Event, {EventConfig, EventPayload} from "./event"; export interface AgileConfigInterface { framework?: Integration | any // Integration = for custom frameworks | any = for existing frameworks like react @@ -98,7 +99,16 @@ export default class Agile { * @param deps Array - An array of state items to depend on * @param computeFunction Function - A function where the return value is the state, ran every time a dep changes */ - public Computed = (computeFunction: () => T, deps?: Array) => new Computed(this, computeFunction, deps); + public Computed = (computeFunction: () => ComputedValueType, deps?: Array) => new Computed(this, computeFunction, deps); + + + //========================================================================================================= + // Event + //========================================================================================================= + /** + * Create a Pulse Event + */ + public Event = (config?: EventConfig) => new Event(this, config); //========================================================================================================= diff --git a/src/api/api.ts b/src/api/index.ts similarity index 100% rename from src/api/api.ts rename to src/api/index.ts diff --git a/src/collection/group.ts b/src/collection/group.ts index 43912551..0b246e5b 100644 --- a/src/collection/group.ts +++ b/src/collection/group.ts @@ -1,5 +1,5 @@ -import {Collection, DefaultDataItem, ItemKey} from "./index"; -import {State} from "../state"; +import Collection, {DefaultDataItem, ItemKey} from "./index"; +import State from "../state"; import Agile from "../agile"; import {defineConfig, normalizeArray} from "../utils"; import {updateGroup} from "./perstist"; @@ -16,7 +16,7 @@ export interface GroupConfigInterface { key?: GroupKey // should be a unique key/name which identifies the group } -export class Group extends State> { +export default class Group extends State> { collection: () => Collection; _output: Array = []; // Output of the group (Note: _value are only the keys of the collection items) diff --git a/src/collection/index.ts b/src/collection/index.ts index e661679b..0d712c89 100644 --- a/src/collection/index.ts +++ b/src/collection/index.ts @@ -1,9 +1,9 @@ import Agile from "../agile"; import Item from "./item"; -import {Group, GroupConfigInterface, GroupKey} from "./group"; -import {Selector, SelectorKey} from "./selector"; +import Group, {GroupConfigInterface, GroupKey} from "./group"; +import Selector, {SelectorKey} from "./selector"; import {copy, defineConfig, flatMerge, isValidObject, normalizeArray} from "../utils"; -import {State, StateKey} from "../state"; +import State, {StateKey} from "../state"; import {StorageKey} from "../storage"; import {persistValue, removeItem, setItem} from "./perstist"; @@ -30,7 +30,7 @@ export type Config = | CollectionConfigInterface | ((collection: Collection) => CollectionConfigInterface); -export class Collection { +export default class Collection { public agileInstance: () => Agile; public config: CollectionConfigInterface; @@ -315,7 +315,7 @@ export class Collection { console.warn(`Agile: Group with name '${groupName}' doesn't exist!`); // Return empty group because it might get annoying to handle with undefined (can check if it exists with group.exists) - const group = new Group(this.agileInstance(), this, [], {key: 'dummy'}); + const group = new Group(this.agileInstance(), this, [], {key: 'dummy'}); group.isPlaceholder = true; return group; } diff --git a/src/collection/item.ts b/src/collection/item.ts index 4070b5c0..72e731bb 100644 --- a/src/collection/item.ts +++ b/src/collection/item.ts @@ -1,5 +1,5 @@ -import {State} from '../state'; -import {Collection, DefaultDataItem} from './index'; +import State from '../state'; +import Collection, {DefaultDataItem} from './index'; export default class Item extends State { diff --git a/src/collection/perstist.ts b/src/collection/perstist.ts index 1cd3c493..20295918 100644 --- a/src/collection/perstist.ts +++ b/src/collection/perstist.ts @@ -1,4 +1,4 @@ -import {Collection, ItemKey} from "./index"; +import Collection, {ItemKey} from "./index"; import Storage, {StorageKey} from "../storage"; import {GroupKey} from "./group"; diff --git a/src/collection/selector.ts b/src/collection/selector.ts index 9ce34719..1de76328 100644 --- a/src/collection/selector.ts +++ b/src/collection/selector.ts @@ -1,5 +1,5 @@ -import {Collection, DefaultDataItem, ItemKey} from "./index"; -import {Computed} from "../computed"; +import Collection, {DefaultDataItem, ItemKey} from "./index"; +import Computed from "../computed"; import Item from "./item"; import {persistValue} from "../state/persist"; import {StorageKey} from "../storage"; @@ -11,7 +11,7 @@ export interface SelectorConfigInterface { key?: SelectorKey // should be a unique key/name which identifies the selector } -export class Selector extends Computed { +export default class Selector extends Computed { public collection: () => Collection; public _id: ItemKey; diff --git a/src/computed/index.ts b/src/computed/index.ts index a47e103e..1b70d2bf 100644 --- a/src/computed/index.ts +++ b/src/computed/index.ts @@ -1,8 +1,8 @@ -import {State} from "../state"; +import State from "../state"; import Agile from "../agile"; import {defineConfig} from "../utils"; -export class Computed extends State { +export default class Computed extends State { public agileInstance: () => Agile; public computeFunction: () => ComputedValueType; diff --git a/src/event/index.ts b/src/event/index.ts index b1968233..5d6fdbcc 100644 --- a/src/event/index.ts +++ b/src/event/index.ts @@ -11,7 +11,7 @@ export interface EventConfig { delay?: number } -export class Event { +export default class Event { public agileInstance: () => Agile; public config: EventConfig; @@ -20,6 +20,7 @@ export class Event { public uses: number = 0; // How often the event has been used private currentTimeout: any; // The current timeout (function) private queue: Array = []; // Queue if something is currently in timeout + // @ts-ignore public payload: PayloadType; // Only holds reference to the PayloadType so that it can be read external (never defined) diff --git a/src/integrations/react.integration.ts b/src/integrations/react.integration.ts index 8b445d91..29e1dcc2 100644 --- a/src/integrations/react.integration.ts +++ b/src/integrations/react.integration.ts @@ -1,11 +1,11 @@ -import {State} from "../state"; +import State from "../state"; import Agile from ".."; import {getAgileInstance, normalizeArray} from "../utils"; import {Integration} from "./use"; import {SubscriptionContainer} from "../sub"; -import {Collection} from "../collection"; -import {Group} from "../collection/group"; -import {Event, EventCallbackFunction} from "../event"; +import Collection from "../collection"; +import Group from "../collection/group"; +import Event, {EventCallbackFunction} from "../event"; //========================================================================================================= diff --git a/src/integrations/test.integration.ts b/src/integrations/test.integration.ts index af7f9c12..f1badd25 100644 --- a/src/integrations/test.integration.ts +++ b/src/integrations/test.integration.ts @@ -1,8 +1,8 @@ -import {State} from "../state"; -import {Collection} from "../collection"; +import State from "../state"; +import Collection from "../collection"; import Agile from "../index"; import {getAgileInstance, normalizeArray} from "../utils"; -import {Group} from "../collection/group"; +import Group from "../collection/group"; //========================================================================================================= diff --git a/src/runtime.ts b/src/runtime.ts index 97febcc8..4ffd9df4 100644 --- a/src/runtime.ts +++ b/src/runtime.ts @@ -1,8 +1,8 @@ -import {State} from "./state"; +import State from "./state"; import Agile from "./agile"; import {copy, defineConfig} from "./utils"; import {CallbackContainer, SubscriptionContainer} from "./sub"; -import {Computed} from "./computed"; +import Computed from "./computed"; export interface JobInterface { state: State diff --git a/src/state/dep.ts b/src/state/dep.ts index 080d1e9b..5a12d81f 100644 --- a/src/state/dep.ts +++ b/src/state/dep.ts @@ -1,5 +1,5 @@ import {SubscriptionContainer} from '../sub'; -import {State} from "./index"; +import State from "./index"; export default class Dep { public deps: Set = new Set(); // Dependencies from the State diff --git a/src/state/index.ts b/src/state/index.ts index 9e5f8f2e..89d3be30 100644 --- a/src/state/index.ts +++ b/src/state/index.ts @@ -11,7 +11,7 @@ export interface PersistSettingsInterface { persistKey?: string | number // Current Persist Key.. for handling twice persisted states } -export class State { +export default class State { public agileInstance: () => Agile; public _key?: StateKey; // should be a unique key/name which identifies the state diff --git a/src/state/persist.ts b/src/state/persist.ts index 5428f9af..d466101c 100644 --- a/src/state/persist.ts +++ b/src/state/persist.ts @@ -1,4 +1,4 @@ -import {State} from "./index"; +import State from "./index"; import Storage, {StorageKey} from "../storage"; diff --git a/src/storage.ts b/src/storage.ts index 8c3da21d..660faf85 100644 --- a/src/storage.ts +++ b/src/storage.ts @@ -1,7 +1,7 @@ import Agile from "./agile"; -import {State} from "./state"; +import State from "./state"; import {isAsyncFunction, isFunction, isJsonString} from "./utils"; -import {Collection} from "./collection"; +import Collection from "./collection"; export type StorageKey = string | number; export interface StorageConfigInterface { diff --git a/src/sub.ts b/src/sub.ts index 285f71fe..684e9d68 100644 --- a/src/sub.ts +++ b/src/sub.ts @@ -1,4 +1,4 @@ -import {State} from "./state"; +import State from "./state"; import Agile from "./agile"; diff --git a/src/utils.ts b/src/utils.ts index f36c27de..93725d88 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,7 +1,7 @@ -import {State} from "./state"; +import State from "./state"; import Agile from "./agile"; -import {Event} from "./event"; -import {Collection} from "./collection"; +import Event from "./event"; +import Collection from "./collection"; //========================================================================================================= diff --git a/test/collection/default.spec.ts b/test/collection/default.spec.ts index ad0835e6..9ccc54ad 100644 --- a/test/collection/default.spec.ts +++ b/test/collection/default.spec.ts @@ -1,8 +1,8 @@ import 'mocha'; import {expect} from 'chai'; import Agile from "../../src"; -import {Group} from "../../src/collection/group"; -import {Selector} from "../../src/collection/selector"; +import Group from "../../src/collection/group"; +import Selector from "../../src/collection/selector"; describe('Default Collection Tests', () => { // Define Agile diff --git a/test/collection/functions/collect.function.spec.ts b/test/collection/functions/collect.function.spec.ts index f15d497c..8d018330 100644 --- a/test/collection/functions/collect.function.spec.ts +++ b/test/collection/functions/collect.function.spec.ts @@ -2,7 +2,7 @@ import 'mocha'; import {expect} from 'chai'; import Agile from "../../../src"; import {useTest} from "../../../src/integrations/test.integration"; -import {Group} from "../../../src/collection/group"; +import Group from "../../../src/collection/group"; describe('Collect Function Tests', () => { // Define Agile diff --git a/test/collection/functions/createGroup.function.spec.ts b/test/collection/functions/createGroup.function.spec.ts index e3d18a16..13da99f8 100644 --- a/test/collection/functions/createGroup.function.spec.ts +++ b/test/collection/functions/createGroup.function.spec.ts @@ -1,7 +1,7 @@ import 'mocha'; import {expect} from 'chai'; import Agile from "../../../src"; -import {Group} from "../../../src/collection/group"; +import Group from "../../../src/collection/group"; describe('createGroup Function Tests', () => { // Define Agile diff --git a/test/collection/functions/createSelector.function.spec.ts b/test/collection/functions/createSelector.function.spec.ts index c2646456..d3572684 100644 --- a/test/collection/functions/createSelector.function.spec.ts +++ b/test/collection/functions/createSelector.function.spec.ts @@ -1,7 +1,7 @@ import 'mocha'; import {expect} from 'chai'; import Agile from "../../../src"; -import {Selector} from "../../../src/collection/selector"; +import Selector from "../../../src/collection/selector"; import Item from "../../../src/collection/item"; describe('createSelector Function Tests', () => { diff --git a/test/collection/functions/findById.function.spec.ts b/test/collection/functions/findById.function.spec.ts index b6ec030a..e3b8a4f6 100644 --- a/test/collection/functions/findById.function.spec.ts +++ b/test/collection/functions/findById.function.spec.ts @@ -1,6 +1,7 @@ import 'mocha'; import {expect} from 'chai'; -import Agile, {State} from "../../../src"; +import Agile from "../../../src"; +import State from "../../../src/state"; describe('FindById Function Tests', () => { // Define Agile diff --git a/test/collection/functions/getGroup.function.spec.ts b/test/collection/functions/getGroup.function.spec.ts index e342dace..a49c5a09 100644 --- a/test/collection/functions/getGroup.function.spec.ts +++ b/test/collection/functions/getGroup.function.spec.ts @@ -1,7 +1,7 @@ import 'mocha'; import {expect} from 'chai'; import Agile from "../../../src"; -import {Group} from "../../../src/collection/group"; +import Group from "../../../src/collection/group"; describe('getGroup Function Tests', () => { // Define Agile diff --git a/test/collection/functions/getSelector.function.spec.ts b/test/collection/functions/getSelector.function.spec.ts index 7bf038fe..4c19ddfd 100644 --- a/test/collection/functions/getSelector.function.spec.ts +++ b/test/collection/functions/getSelector.function.spec.ts @@ -1,7 +1,7 @@ import 'mocha'; import {expect} from 'chai'; import Agile from "../../../src"; -import {Selector} from "../../../src/collection/selector"; +import Selector from "../../../src/collection/selector"; describe('getSelector Function Tests', () => { // Define Agile diff --git a/test/collection/functions/getValueById.function.spec.ts b/test/collection/functions/getValueById.function.spec.ts index f495cf17..0eff6acb 100644 --- a/test/collection/functions/getValueById.function.spec.ts +++ b/test/collection/functions/getValueById.function.spec.ts @@ -1,6 +1,6 @@ import 'mocha'; import {expect} from 'chai'; -import Agile, {State} from "../../../src"; +import Agile from "../../../src"; describe('GetValueById Function Tests', () => { // Define Agile diff --git a/test/collection/functions/update.function.spec.ts b/test/collection/functions/update.function.spec.ts index e2bd6dfb..1191a909 100644 --- a/test/collection/functions/update.function.spec.ts +++ b/test/collection/functions/update.function.spec.ts @@ -2,7 +2,7 @@ import 'mocha'; import {expect} from 'chai'; import Agile from "../../../src"; import {useTest} from "../../../src/integrations/test.integration"; -import {Group} from "../../../src/collection/group"; +import Group from "../../../src/collection/group"; describe('Update Function Tests', () => { let rerenderCount = 0; diff --git a/test/collection/group/default.spec.ts b/test/collection/group/default.spec.ts index 8ea5ed66..071ec249 100644 --- a/test/collection/group/default.spec.ts +++ b/test/collection/group/default.spec.ts @@ -1,7 +1,7 @@ import Agile from "../../../src"; import {useTest} from "../../../src/integrations/test.integration"; import {expect} from "chai"; -import {Group} from "../../../src/collection/group"; +import Group from "../../../src/collection/group"; describe('Default Group Tests', () => { // Define Agile diff --git a/test/collection/group/functions/add.function.spec.ts b/test/collection/group/functions/add.function.spec.ts index 7227b084..35a7c6ad 100644 --- a/test/collection/group/functions/add.function.spec.ts +++ b/test/collection/group/functions/add.function.spec.ts @@ -1,7 +1,7 @@ import Agile from "../../../../src"; import {useTest} from "../../../../src/integrations/test.integration"; import {expect} from "chai"; -import {Group} from "../../../../src/collection/group"; +import Group from "../../../../src/collection/group"; describe('Add function Tests', () => { let rerenderCount = 0; diff --git a/test/collection/group/functions/has.function.spec.ts b/test/collection/group/functions/has.function.spec.ts index 3a49b42d..aa0fd782 100644 --- a/test/collection/group/functions/has.function.spec.ts +++ b/test/collection/group/functions/has.function.spec.ts @@ -1,6 +1,6 @@ import Agile from "../../../../src"; import {expect} from "chai"; -import {Group} from "../../../../src/collection/group"; +import Group from "../../../../src/collection/group"; describe('Has function Tests', () => { // Define Agile diff --git a/test/collection/group/functions/remove.function.spec.ts b/test/collection/group/functions/remove.function.spec.ts index 02e5ba1e..94702064 100644 --- a/test/collection/group/functions/remove.function.spec.ts +++ b/test/collection/group/functions/remove.function.spec.ts @@ -1,7 +1,7 @@ import Agile from "../../../../src"; import {useTest} from "../../../../src/integrations/test.integration"; import {expect} from "chai"; -import {Group} from "../../../../src/collection/group"; +import Group from "../../../../src/collection/group"; describe('Add function Tests', () => { let rerenderCount = 0; diff --git a/test/collection/selector/default.spec.ts b/test/collection/selector/default.spec.ts index fe57b801..cd40b1a7 100644 --- a/test/collection/selector/default.spec.ts +++ b/test/collection/selector/default.spec.ts @@ -1,7 +1,7 @@ import Agile from "../../../src"; import {useTest} from "../../../src/integrations/test.integration"; import {expect} from "chai"; -import {Selector} from "../../../src/collection/selector"; +import Selector from "../../../src/collection/selector"; import Item from "../../../src/collection/item"; describe('Default Selector Tests', () => { diff --git a/test/collection/selector/functions/select.function.spec.ts b/test/collection/selector/functions/select.function.spec.ts index 46ef828d..9219372d 100644 --- a/test/collection/selector/functions/select.function.spec.ts +++ b/test/collection/selector/functions/select.function.spec.ts @@ -1,7 +1,7 @@ import Agile from "../../../../src"; import {useTest} from "../../../../src/integrations/test.integration"; import {expect} from "chai"; -import {Selector} from "../../../../src/collection/selector"; +import Selector from "../../../../src/collection/selector"; import Item from "../../../../src/collection/item"; describe('select Function Tests', () => { diff --git a/test/computed/default.ts b/test/computed/default.ts index ef6b06f7..e208b642 100644 --- a/test/computed/default.ts +++ b/test/computed/default.ts @@ -1,7 +1,7 @@ import 'mocha'; import {expect} from 'chai'; import Agile from "../../src"; -import {Computed} from "../../src/computed"; +import Computed from "../../src/computed"; import {useTest} from "../../src/integrations/test.integration"; describe('Default Computed Tests', () => { diff --git a/test/computed/functions/updateComputeFunction.function.spec.ts b/test/computed/functions/updateComputeFunction.function.spec.ts index e5a5712f..f742c8c5 100644 --- a/test/computed/functions/updateComputeFunction.function.spec.ts +++ b/test/computed/functions/updateComputeFunction.function.spec.ts @@ -1,7 +1,7 @@ import 'mocha'; import {expect} from 'chai'; import Agile from "../../../src"; -import {Computed} from "../../../src/computed"; +import Computed from "../../../src/computed"; import {useTest} from "../../../src/integrations/test.integration"; describe('updateComputeFunction Function tests', () => { From 112f68ed2bf4c0c9b2b2515b47a8269c8ee804d2 Mon Sep 17 00:00:00 2001 From: Benno Kohrs Date: Wed, 9 Sep 2020 21:11:28 +0200 Subject: [PATCH 05/25] Updated ts ignore because of annoying errors --- tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index 3f0e2577..61d65510 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -26,7 +26,7 @@ /* Strict Type-Checking Options */ "strict": true, /* Enable all strict type-checking options. */ - // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ + "noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */ // "strictNullChecks": true, /* Enable strict null checks. */ // "strictFunctionTypes": true, /* Enable strict checking of function types. */ // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ From c3f861e33b5cf449435dd8a0bedddac8e8c47ca8 Mon Sep 17 00:00:00 2001 From: Benno Kohrs Date: Wed, 9 Sep 2020 21:39:50 +0200 Subject: [PATCH 06/25] Made some small naming changes --- src/agile.ts | 8 ++++---- src/collection/index.ts | 4 ++-- src/event/index.ts | 9 +++++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/agile.ts b/src/agile.ts index 7421b8ca..7d9b0f8a 100644 --- a/src/agile.ts +++ b/src/agile.ts @@ -3,10 +3,10 @@ import use, {Integration} from "./integrations/use"; import SubController from "./sub"; import State from "./state"; import Storage, {StorageConfigInterface} from "./storage"; -import Collection, {Config, DefaultDataItem} from "./collection"; +import Collection, {CollectionConfig, DefaultDataItem} from "./collection"; import Computed from "./computed"; import API, {apiConfig} from "./api"; -import Event, {EventConfig, EventPayload} from "./event"; +import Event, {EventConfig, DefaultEventPayload} from "./event"; export interface AgileConfigInterface { framework?: Integration | any // Integration = for custom frameworks | any = for existing frameworks like react @@ -88,7 +88,7 @@ export default class Agile { /** * Create Agile Collection */ - public Collection = (config?: Config) => new Collection(this, config); + public Collection = (config?: CollectionConfig) => new Collection(this, config); //========================================================================================================= @@ -108,7 +108,7 @@ export default class Agile { /** * Create a Pulse Event */ - public Event = (config?: EventConfig) => new Event(this, config); + public Event = (config?: EventConfig) => new Event(this, config); //========================================================================================================= diff --git a/src/collection/index.ts b/src/collection/index.ts index 0d712c89..77e743f0 100644 --- a/src/collection/index.ts +++ b/src/collection/index.ts @@ -26,7 +26,7 @@ export interface CollectOptionsInterface { background?: boolean // If the action should happen in the background -> no rerender } -export type Config = +export type CollectionConfig = | CollectionConfigInterface | ((collection: Collection) => CollectionConfigInterface); @@ -43,7 +43,7 @@ export default class Collection { public groups: { [key: string]: Group } = {}; public selectors: { [key: string]: Selector } = {}; - constructor(agileInstance: Agile, config: Config = {}) { + constructor(agileInstance: Agile, config: CollectionConfig = {}) { this.agileInstance = () => agileInstance; // If collection config is a function, execute and assign to config diff --git a/src/event/index.ts b/src/event/index.ts index 5d6fdbcc..054c10b0 100644 --- a/src/event/index.ts +++ b/src/event/index.ts @@ -1,17 +1,18 @@ import Agile from "../agile"; import {defineConfig} from "../utils"; -export type EventPayload = { [key: string]: any }; -export type EventCallbackFunction = (payload?: PayloadType) => void; +export type DefaultEventPayload = { [key: string]: any }; +export type EventCallbackFunction = (payload?: PayloadType) => void; +export type EventKey = string | number; export interface EventConfig { - key?: string + key?: EventKey enabled?: boolean maxUses?: number delay?: number } -export default class Event { +export default class Event { public agileInstance: () => Agile; public config: EventConfig; From e2dccecb063157a34ef82a4475ed210e52eba550 Mon Sep 17 00:00:00 2001 From: Benno Kohrs Date: Wed, 9 Sep 2020 21:47:54 +0200 Subject: [PATCH 07/25] Updated integration folder structure --- src/index.ts | 4 +- src/integrations/react.integration.ts | 241 ------------------ src/integrations/react/hooks/AgileHOC.ts | 92 +++++++ src/integrations/react/hooks/useAgile.ts | 82 ++++++ src/integrations/react/hooks/useEvent.ts | 27 ++ src/integrations/react/index.ts | 7 + src/integrations/react/react.integration.ts | 31 +++ .../{ => test}/test.integration.ts | 10 +- src/integrations/use.ts | 2 +- .../functions/collect.function.spec.ts | 2 +- .../functions/remove.function.spec.ts | 2 +- .../functions/update.function.spec.ts | 2 +- test/collection/group/default.spec.ts | 2 +- .../group/functions/add.function.spec.ts | 2 +- .../group/functions/remove.function.spec.ts | 2 +- test/collection/selector/default.spec.ts | 2 +- .../functions/select.function.spec.ts | 2 +- test/computed/default.ts | 2 +- .../updateComputeFunction.function.spec.ts | 2 +- test/state/functions/patch.function.spec.ts | 2 +- test/state/functions/reset.function.spec.ts | 2 +- test/state/functions/set.function.spec.ts | 2 +- test/state/functions/undo.function.spec.ts | 2 +- 23 files changed, 260 insertions(+), 264 deletions(-) delete mode 100644 src/integrations/react.integration.ts create mode 100644 src/integrations/react/hooks/AgileHOC.ts create mode 100644 src/integrations/react/hooks/useAgile.ts create mode 100644 src/integrations/react/hooks/useEvent.ts create mode 100644 src/integrations/react/index.ts create mode 100644 src/integrations/react/react.integration.ts rename src/integrations/{ => test}/test.integration.ts (92%) diff --git a/src/index.ts b/src/index.ts index 9dc38d0f..58cb5d95 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,8 +3,6 @@ import Agile from './agile'; export * from './state'; // Framework based exports -export {useAgile} from './integrations/react.integration'; -export {AgileHOC} from './integrations/react.integration'; -export {useEvent} from './integrations/react.integration'; +export * from './integrations/react'; export default Agile; diff --git a/src/integrations/react.integration.ts b/src/integrations/react.integration.ts deleted file mode 100644 index 29e1dcc2..00000000 --- a/src/integrations/react.integration.ts +++ /dev/null @@ -1,241 +0,0 @@ -import State from "../state"; -import Agile from ".."; -import {getAgileInstance, normalizeArray} from "../utils"; -import {Integration} from "./use"; -import {SubscriptionContainer} from "../sub"; -import Collection from "../collection"; -import Group from "../collection/group"; -import Event, {EventCallbackFunction} from "../event"; - - -//========================================================================================================= -// Agile HOC for React classes -//========================================================================================================= - -export function AgileHOC(ReactComponent: any, deps?: Array | { [key: string]: State } | State, agileInstance?: Agile) { - let depsArray: Array; - let depsObject: { [key: string]: State }; - - if (deps instanceof State || Array.isArray(deps)) { - // Normalize Dependencies - depsArray = normalizeArray(deps || []); - - // Get Agile Instance - if (!agileInstance) { - if (depsArray.length > 0) { - const tempAgileInstance = getAgileInstance(depsArray[0]); - agileInstance = tempAgileInstance || undefined; - } else { - console.warn("Agile: Please don't pass an empty array!"); - } - } - } else if (typeof deps === "object") { - depsObject = deps; - - // Get Agile Instance - if (!agileInstance) { - const objectKeys = Object.keys(depsObject); - if (objectKeys.length > 0) { - const tempAgileInstance = getAgileInstance(depsObject[objectKeys[0]]); - agileInstance = tempAgileInstance || undefined; - } else { - console.warn("Agile: Please don't pass an empty object!"); - } - } - } else { - console.error("Agile: No Valid AgileHOC properties"); - return ReactComponent; - } - - // Check if agile Instance exists - if (!agileInstance) { - console.error("Agile: Failed to get Agile Instance"); - return ReactComponent; - } - - // Get React constructor - const React = agileInstance.integration?.frameworkConstructor; - if (!React) { - console.error("Agile: Failed to get Framework Constructor"); - return ReactComponent; - } - - return class extends React.Component { - public componentContainer: SubscriptionContainer | null = null; // Will be set in registerSubscription (sub.ts) - - public updatedProps = this.props; - - constructor(props: any) { - super(props); - - // Create HOC based Subscription with Array (Rerenders will here be caused via force Update) - if (depsArray) - agileInstance?.subController.subscribeWithSubsArray(this, depsArray); - - // Create HOC based Subscription with Object - if (depsObject) { - const response = agileInstance?.subController.subscribeWithSubsObject(this, depsObject); - this.updatedProps = { - ...props, - ...response?.props - } - - // Defines State for causing rerender (will be called in updateMethod) - this.state = depsObject; - } - } - - componentDidMount() { - if (agileInstance?.config.waitForMount) - agileInstance?.subController.mount(this); - } - - componentWillUnmount() { - agileInstance?.subController.unsubscribe(this); - } - - render() { - return React.createElement(ReactComponent, this.updatedProps); - } - }; -} - - -//========================================================================================================= -// Use Agile Hook -//========================================================================================================= - -// Array Type -// https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-1.html -type AgileHookArrayType = { - [K in keyof T]: T[K] extends Group ? U[] - : T[K] extends State ? U - : T[K] extends Collection ? U[] - : T[K] extends undefined ? undefined - : never -}; - -// No Array Type -type AgileHookType = T extends Group ? U[] - : T extends State ? U - : T extends Collection ? U[] - : T extends undefined ? undefined - : never; - -// Array -export function useAgile>(deps: X, agileInstance?: Agile): AgileHookArrayType; - -// No Array -export function useAgile(deps: X, agileInstance?: Agile): AgileHookType; - -export function useAgile, Y extends State | Collection | undefined>(deps: X | Y, agileInstance?: Agile): AgileHookArrayType | AgileHookType { - // Normalize Dependencies - let depsArray = normalizeArray(deps) - .map(item => item instanceof Collection ? item.getGroup(item.config.defaultGroupKey || 'default') : item) - .filter(item => item !== undefined) as State[]; - - // Function which creates the return value - const getReturnValue = (depsArray: State[]): AgileHookArrayType | AgileHookType => { - // Return Public Value of State - if (depsArray.length === 1 && !Array.isArray(deps)) - return depsArray[0]?.getPublicValue() as AgileHookType; - - // Return Public Value of State in Array - return depsArray.map(dep => { - return dep.getPublicValue(); - }) as AgileHookArrayType; - } - - // Get Agile Instance - if (!agileInstance) { - const tempAgileInstance = getAgileInstance(depsArray[0]); - if (!tempAgileInstance) { - console.error("Agile: Failed to get Agile Instance"); - return getReturnValue(depsArray); - } - agileInstance = tempAgileInstance; - } - - // Get React constructor - const React = agileInstance.integration?.frameworkConstructor; - if (!React) { - console.error("Agile: Failed to get Framework Constructor"); - return getReturnValue(depsArray); - } - - // This is a Trigger State used to force the component to Re-render - const [_, set_] = React.useState({}); - - React.useEffect(function () { - // Create a callback base subscription, Callback invokes re-render Trigger - const subscriptionContainer = agileInstance?.subController.subscribeWithSubsArray( - () => { - set_({}); - }, - depsArray - ); - - // Unsubscribe on Unmount - return () => agileInstance?.subController.unsubscribe(subscriptionContainer); - }, []); - - return getReturnValue(depsArray); -} - - -//========================================================================================================= -// Use Event Hook -//========================================================================================================= - -export function useEvent(event: E, callback: EventCallbackFunction, agileInstance?: Agile) { - // Get Agile Instance - if (!agileInstance) { - const tempAgileInstance = getAgileInstance(event); - if (!tempAgileInstance) { - console.error("Agile: Failed to get Agile Instance"); - return; - } - agileInstance = tempAgileInstance; - } - - // Get React constructor - const React = agileInstance.integration?.frameworkConstructor; - if (!React) { - console.error("Agile: Failed to get Framework Constructor"); - return; - } - - React.useEffect(function () { - // Call event on component mount and remove event on component unmount - return event.on(callback); - }, []); -} - - -//========================================================================================================= -// Framework Integration -//========================================================================================================= - -const reactIntegration: Integration = { - name: 'react', - bind(agileInstance: Agile) { - // Not sure if usePulse should get into the pulseInstance - // pulseInstance.usePulse = (deps: Array) => usePulse(deps, pulseInstance); - // if (agileInstance.config.logJobs) console.log("Agile: Successfully binded React to Agile") - }, - updateMethod(componentInstance: any, updatedData: Object) { - // UpdatedData will be empty if the AgileHOC doesn't get an object as deps - - if (Object.keys(updatedData).length !== 0) { - // Update Props - componentInstance.updatedProps = {...componentInstance.updatedProps, ...updatedData}; - - // Set State - componentInstance.setState(updatedData); - } else { - componentInstance.forceUpdate(); - } - } -}; - -export default reactIntegration; diff --git a/src/integrations/react/hooks/AgileHOC.ts b/src/integrations/react/hooks/AgileHOC.ts new file mode 100644 index 00000000..f73e46c8 --- /dev/null +++ b/src/integrations/react/hooks/AgileHOC.ts @@ -0,0 +1,92 @@ +import State from "../../../state"; +import Agile from "../../../index"; +import {getAgileInstance, normalizeArray} from "../../../utils"; +import {SubscriptionContainer} from "../../../sub"; + +export function AgileHOC(ReactComponent: any, deps?: Array | { [key: string]: State } | State, agileInstance?: Agile) { + let depsArray: Array; + let depsObject: { [key: string]: State }; + + if (deps instanceof State || Array.isArray(deps)) { + // Normalize Dependencies + depsArray = normalizeArray(deps || []); + + // Get Agile Instance + if (!agileInstance) { + if (depsArray.length > 0) { + const tempAgileInstance = getAgileInstance(depsArray[0]); + agileInstance = tempAgileInstance || undefined; + } else { + console.warn("Agile: Please don't pass an empty array!"); + } + } + } else if (typeof deps === "object") { + depsObject = deps; + + // Get Agile Instance + if (!agileInstance) { + const objectKeys = Object.keys(depsObject); + if (objectKeys.length > 0) { + const tempAgileInstance = getAgileInstance(depsObject[objectKeys[0]]); + agileInstance = tempAgileInstance || undefined; + } else { + console.warn("Agile: Please don't pass an empty object!"); + } + } + } else { + console.error("Agile: No Valid AgileHOC properties"); + return ReactComponent; + } + + // Check if agile Instance exists + if (!agileInstance) { + console.error("Agile: Failed to get Agile Instance"); + return ReactComponent; + } + + // Get React constructor + const React = agileInstance.integration?.frameworkConstructor; + if (!React) { + console.error("Agile: Failed to get Framework Constructor"); + return ReactComponent; + } + + return class extends React.Component { + public componentContainer: SubscriptionContainer | null = null; // Will be set in registerSubscription (sub.ts) + + public updatedProps = this.props; + + constructor(props: any) { + super(props); + + // Create HOC based Subscription with Array (Rerenders will here be caused via force Update) + if (depsArray) + agileInstance?.subController.subscribeWithSubsArray(this, depsArray); + + // Create HOC based Subscription with Object + if (depsObject) { + const response = agileInstance?.subController.subscribeWithSubsObject(this, depsObject); + this.updatedProps = { + ...props, + ...response?.props + } + + // Defines State for causing rerender (will be called in updateMethod) + this.state = depsObject; + } + } + + componentDidMount() { + if (agileInstance?.config.waitForMount) + agileInstance?.subController.mount(this); + } + + componentWillUnmount() { + agileInstance?.subController.unsubscribe(this); + } + + render() { + return React.createElement(ReactComponent, this.updatedProps); + } + }; +} diff --git a/src/integrations/react/hooks/useAgile.ts b/src/integrations/react/hooks/useAgile.ts new file mode 100644 index 00000000..5746fa71 --- /dev/null +++ b/src/integrations/react/hooks/useAgile.ts @@ -0,0 +1,82 @@ +import Group from "../../../collection/group"; +import State from "../../../state"; +import Collection from "../../../collection"; +import Agile from "../../../index"; +import {getAgileInstance, normalizeArray} from "../../../utils"; + +// Array Type +// https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-1.html +type AgileHookArrayType = { + [K in keyof T]: T[K] extends Group ? U[] + : T[K] extends State ? U + : T[K] extends Collection ? U[] + : T[K] extends undefined ? undefined + : never +}; + +// No Array Type +type AgileHookType = T extends Group ? U[] + : T extends State ? U + : T extends Collection ? U[] + : T extends undefined ? undefined + : never; + +// Array +export function useAgile>(deps: X, agileInstance?: Agile): AgileHookArrayType; + +// No Array +export function useAgile(deps: X, agileInstance?: Agile): AgileHookType; + +export function useAgile, Y extends State | Collection | undefined>(deps: X | Y, agileInstance?: Agile): AgileHookArrayType | AgileHookType { + // Normalize Dependencies + let depsArray = normalizeArray(deps) + .map(item => item instanceof Collection ? item.getGroup(item.config.defaultGroupKey || 'default') : item) + .filter(item => item !== undefined) as State[]; + + // Function which creates the return value + const getReturnValue = (depsArray: State[]): AgileHookArrayType | AgileHookType => { + // Return Public Value of State + if (depsArray.length === 1 && !Array.isArray(deps)) + return depsArray[0]?.getPublicValue() as AgileHookType; + + // Return Public Value of State in Array + return depsArray.map(dep => { + return dep.getPublicValue(); + }) as AgileHookArrayType; + } + + // Get Agile Instance + if (!agileInstance) { + const tempAgileInstance = getAgileInstance(depsArray[0]); + if (!tempAgileInstance) { + console.error("Agile: Failed to get Agile Instance"); + return getReturnValue(depsArray); + } + agileInstance = tempAgileInstance; + } + + // Get React constructor + const React = agileInstance.integration?.frameworkConstructor; + if (!React) { + console.error("Agile: Failed to get Framework Constructor"); + return getReturnValue(depsArray); + } + + // This is a Trigger State used to force the component to Re-render + const [_, set_] = React.useState({}); + + React.useEffect(function () { + // Create a callback base subscription, Callback invokes re-render Trigger + const subscriptionContainer = agileInstance?.subController.subscribeWithSubsArray( + () => { + set_({}); + }, + depsArray + ); + + // Unsubscribe on Unmount + return () => agileInstance?.subController.unsubscribe(subscriptionContainer); + }, []); + + return getReturnValue(depsArray); +} diff --git a/src/integrations/react/hooks/useEvent.ts b/src/integrations/react/hooks/useEvent.ts new file mode 100644 index 00000000..7bf99370 --- /dev/null +++ b/src/integrations/react/hooks/useEvent.ts @@ -0,0 +1,27 @@ +import Event, {EventCallbackFunction} from "../../../event"; +import Agile from "../../../index"; +import {getAgileInstance} from "../../../utils"; + +export function useEvent(event: E, callback: EventCallbackFunction, agileInstance?: Agile) { + // Get Agile Instance + if (!agileInstance) { + const tempAgileInstance = getAgileInstance(event); + if (!tempAgileInstance) { + console.error("Agile: Failed to get Agile Instance"); + return; + } + agileInstance = tempAgileInstance; + } + + // Get React constructor + const React = agileInstance.integration?.frameworkConstructor; + if (!React) { + console.error("Agile: Failed to get Framework Constructor"); + return; + } + + React.useEffect(function () { + // Call event on component mount and remove event on component unmount + return event.on(callback); + }, []); +} diff --git a/src/integrations/react/index.ts b/src/integrations/react/index.ts new file mode 100644 index 00000000..e8f35d34 --- /dev/null +++ b/src/integrations/react/index.ts @@ -0,0 +1,7 @@ +import reactIntegration from "./react.integration"; + +export {useAgile} from './hooks/useAgile'; +export {AgileHOC} from './hooks/AgileHOC'; +export {useEvent} from './hooks/useEvent'; + +export default reactIntegration; diff --git a/src/integrations/react/react.integration.ts b/src/integrations/react/react.integration.ts new file mode 100644 index 00000000..6fe0e05c --- /dev/null +++ b/src/integrations/react/react.integration.ts @@ -0,0 +1,31 @@ +import Agile from "../../index"; +import {Integration} from "../use"; + + +//========================================================================================================= +// Framework Integration +//========================================================================================================= + +const reactIntegration: Integration = { + name: 'react', + bind(agileInstance: Agile) { + // Not sure if usePulse should get into the pulseInstance + // pulseInstance.usePulse = (deps: Array) => usePulse(deps, pulseInstance); + // if (agileInstance.config.logJobs) console.log("Agile: Successfully binded React to Agile") + }, + updateMethod(componentInstance: any, updatedData: Object) { + // UpdatedData will be empty if the AgileHOC doesn't get an object as deps + + if (Object.keys(updatedData).length !== 0) { + // Update Props + componentInstance.updatedProps = {...componentInstance.updatedProps, ...updatedData}; + + // Set State + componentInstance.setState(updatedData); + } else { + componentInstance.forceUpdate(); + } + } +}; + +export default reactIntegration; diff --git a/src/integrations/test.integration.ts b/src/integrations/test/test.integration.ts similarity index 92% rename from src/integrations/test.integration.ts rename to src/integrations/test/test.integration.ts index f1badd25..c1bfd509 100644 --- a/src/integrations/test.integration.ts +++ b/src/integrations/test/test.integration.ts @@ -1,8 +1,8 @@ -import State from "../state"; -import Collection from "../collection"; -import Agile from "../index"; -import {getAgileInstance, normalizeArray} from "../utils"; -import Group from "../collection/group"; +import State from "../../state"; +import Collection from "../../collection"; +import Agile from "../../index"; +import {getAgileInstance, normalizeArray} from "../../utils"; +import Group from "../../collection/group"; //========================================================================================================= diff --git a/src/integrations/use.ts b/src/integrations/use.ts index f5cb2dd2..c9638021 100644 --- a/src/integrations/use.ts +++ b/src/integrations/use.ts @@ -1,5 +1,5 @@ import Agile from "../agile"; -import reactIntegration from "../integrations/react.integration"; +import reactIntegration from "./react"; export interface Integration { ready?: boolean; diff --git a/test/collection/functions/collect.function.spec.ts b/test/collection/functions/collect.function.spec.ts index 8d018330..85a507c4 100644 --- a/test/collection/functions/collect.function.spec.ts +++ b/test/collection/functions/collect.function.spec.ts @@ -1,7 +1,7 @@ import 'mocha'; import {expect} from 'chai'; import Agile from "../../../src"; -import {useTest} from "../../../src/integrations/test.integration"; +import {useTest} from "../../../src/integrations/test/test.integration"; import Group from "../../../src/collection/group"; describe('Collect Function Tests', () => { diff --git a/test/collection/functions/remove.function.spec.ts b/test/collection/functions/remove.function.spec.ts index 9b1a13f7..59ce702b 100644 --- a/test/collection/functions/remove.function.spec.ts +++ b/test/collection/functions/remove.function.spec.ts @@ -1,7 +1,7 @@ import 'mocha'; import {expect} from 'chai'; import Agile from "../../../src"; -import {useTest} from "../../../src/integrations/test.integration"; +import {useTest} from "../../../src/integrations/test/test.integration"; import Item from "../../../src/collection/item"; describe('Remove Function Tests', () => { diff --git a/test/collection/functions/update.function.spec.ts b/test/collection/functions/update.function.spec.ts index 1191a909..2c208a13 100644 --- a/test/collection/functions/update.function.spec.ts +++ b/test/collection/functions/update.function.spec.ts @@ -1,7 +1,7 @@ import 'mocha'; import {expect} from 'chai'; import Agile from "../../../src"; -import {useTest} from "../../../src/integrations/test.integration"; +import {useTest} from "../../../src/integrations/test/test.integration"; import Group from "../../../src/collection/group"; describe('Update Function Tests', () => { diff --git a/test/collection/group/default.spec.ts b/test/collection/group/default.spec.ts index 071ec249..e8527e04 100644 --- a/test/collection/group/default.spec.ts +++ b/test/collection/group/default.spec.ts @@ -1,5 +1,5 @@ import Agile from "../../../src"; -import {useTest} from "../../../src/integrations/test.integration"; +import {useTest} from "../../../src/integrations/test/test.integration"; import {expect} from "chai"; import Group from "../../../src/collection/group"; diff --git a/test/collection/group/functions/add.function.spec.ts b/test/collection/group/functions/add.function.spec.ts index 35a7c6ad..8c11079a 100644 --- a/test/collection/group/functions/add.function.spec.ts +++ b/test/collection/group/functions/add.function.spec.ts @@ -1,5 +1,5 @@ import Agile from "../../../../src"; -import {useTest} from "../../../../src/integrations/test.integration"; +import {useTest} from "../../../../src/integrations/test/test.integration"; import {expect} from "chai"; import Group from "../../../../src/collection/group"; diff --git a/test/collection/group/functions/remove.function.spec.ts b/test/collection/group/functions/remove.function.spec.ts index 94702064..aa9cc7a7 100644 --- a/test/collection/group/functions/remove.function.spec.ts +++ b/test/collection/group/functions/remove.function.spec.ts @@ -1,5 +1,5 @@ import Agile from "../../../../src"; -import {useTest} from "../../../../src/integrations/test.integration"; +import {useTest} from "../../../../src/integrations/test/test.integration"; import {expect} from "chai"; import Group from "../../../../src/collection/group"; diff --git a/test/collection/selector/default.spec.ts b/test/collection/selector/default.spec.ts index cd40b1a7..7d0734d0 100644 --- a/test/collection/selector/default.spec.ts +++ b/test/collection/selector/default.spec.ts @@ -1,5 +1,5 @@ import Agile from "../../../src"; -import {useTest} from "../../../src/integrations/test.integration"; +import {useTest} from "../../../src/integrations/test/test.integration"; import {expect} from "chai"; import Selector from "../../../src/collection/selector"; import Item from "../../../src/collection/item"; diff --git a/test/collection/selector/functions/select.function.spec.ts b/test/collection/selector/functions/select.function.spec.ts index 9219372d..2e79e823 100644 --- a/test/collection/selector/functions/select.function.spec.ts +++ b/test/collection/selector/functions/select.function.spec.ts @@ -1,5 +1,5 @@ import Agile from "../../../../src"; -import {useTest} from "../../../../src/integrations/test.integration"; +import {useTest} from "../../../../src/integrations/test/test.integration"; import {expect} from "chai"; import Selector from "../../../../src/collection/selector"; import Item from "../../../../src/collection/item"; diff --git a/test/computed/default.ts b/test/computed/default.ts index e208b642..3ae5b5ae 100644 --- a/test/computed/default.ts +++ b/test/computed/default.ts @@ -2,7 +2,7 @@ import 'mocha'; import {expect} from 'chai'; import Agile from "../../src"; import Computed from "../../src/computed"; -import {useTest} from "../../src/integrations/test.integration"; +import {useTest} from "../../src/integrations/test/test.integration"; describe('Default Computed Tests', () => { // Define Agile diff --git a/test/computed/functions/updateComputeFunction.function.spec.ts b/test/computed/functions/updateComputeFunction.function.spec.ts index f742c8c5..41c9c900 100644 --- a/test/computed/functions/updateComputeFunction.function.spec.ts +++ b/test/computed/functions/updateComputeFunction.function.spec.ts @@ -2,7 +2,7 @@ import 'mocha'; import {expect} from 'chai'; import Agile from "../../../src"; import Computed from "../../../src/computed"; -import {useTest} from "../../../src/integrations/test.integration"; +import {useTest} from "../../../src/integrations/test/test.integration"; describe('updateComputeFunction Function tests', () => { let rerenderCount = 0; diff --git a/test/state/functions/patch.function.spec.ts b/test/state/functions/patch.function.spec.ts index 0308373f..9aa14a91 100644 --- a/test/state/functions/patch.function.spec.ts +++ b/test/state/functions/patch.function.spec.ts @@ -1,7 +1,7 @@ import 'mocha'; import {expect} from 'chai'; import Agile from "../../../src"; -import {useTest} from "../../../src/integrations/test.integration"; +import {useTest} from "../../../src/integrations/test/test.integration"; describe('Patch Function Tests', () => { let rerenderCount = 0; diff --git a/test/state/functions/reset.function.spec.ts b/test/state/functions/reset.function.spec.ts index a6f24ff3..f46f52fe 100644 --- a/test/state/functions/reset.function.spec.ts +++ b/test/state/functions/reset.function.spec.ts @@ -1,7 +1,7 @@ import 'mocha'; import {expect} from 'chai'; import Agile from "../../../src"; -import {useTest} from "../../../src/integrations/test.integration"; +import {useTest} from "../../../src/integrations/test/test.integration"; describe('Reset Function Tests', () => { let rerenderCount = 0; diff --git a/test/state/functions/set.function.spec.ts b/test/state/functions/set.function.spec.ts index 49afcccf..d3476a2f 100644 --- a/test/state/functions/set.function.spec.ts +++ b/test/state/functions/set.function.spec.ts @@ -1,7 +1,7 @@ import 'mocha'; import {expect} from 'chai'; import Agile from "../../../src"; -import {useTest} from "../../../src/integrations/test.integration"; +import {useTest} from "../../../src/integrations/test/test.integration"; describe('Set Function Tests', () => { let rerenderCount = 0; diff --git a/test/state/functions/undo.function.spec.ts b/test/state/functions/undo.function.spec.ts index 61e92dde..7792d974 100644 --- a/test/state/functions/undo.function.spec.ts +++ b/test/state/functions/undo.function.spec.ts @@ -1,7 +1,7 @@ import 'mocha'; import {expect} from 'chai'; import Agile from "../../../src"; -import {useTest} from "../../../src/integrations/test.integration"; +import {useTest} from "../../../src/integrations/test/test.integration"; describe('Undo Function Tests', () => { let rerenderCount = 0; From 8c6b09e5535f42bf9773f45ae6c26a224d8542ad Mon Sep 17 00:00:00 2001 From: BennoDev <57860196+bennodev19@users.noreply.github.com> Date: Wed, 9 Sep 2020 21:56:36 +0200 Subject: [PATCH 08/25] Fixed typo in readme --- ReadMe.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ReadMe.md b/ReadMe.md index 8e4a9fac..0bc6c2c9 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -4,10 +4,10 @@ _Agile is a global state and logic framework for reactive Typescript & Javascrip #### Agile is strongly inspired by [PulseJs](https://github.com/pulse-framework/pulse) It was mainly created to learn how Pulse works under the hood, and it was fun to 'copy' and optimize PulseJs. -I will use this project mainly for my own project because here the code style is after my taste.. +I will use this project mainly for my own projects because here the code style is after my taste.. So I can change things quickly and don't have to deal with a big framework which is used by many people and must function perfectly. -##### Feel free to use it but be aware that it is optimized to my needs and has no docs +##### Feel free to use it but be aware that it is optimized to my needs and has no [docs](https://pulsejs.org/)
From fc85daa4bb0097026f568bbb6494521323db75c1 Mon Sep 17 00:00:00 2001 From: BennoDev <57860196+bennodev19@users.noreply.github.com> Date: Wed, 9 Sep 2020 21:57:31 +0200 Subject: [PATCH 09/25] Increased version in readMe --- ReadMe.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ReadMe.md b/ReadMe.md index 0bc6c2c9..6cb11c28 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -1,4 +1,4 @@ -# Agile Framework `1.0` +# Agile Framework `1.1` _Agile is a global state and logic framework for reactive Typescript & Javascript applications. Supporting frameworks like React and React Native._ From 5e0053c3766ef74a71797e9cd808f698daa0cbfc Mon Sep 17 00:00:00 2001 From: Benno Kohrs Date: Sat, 12 Sep 2020 12:58:10 +0200 Subject: [PATCH 10/25] Changed folder structure of test hooks and added useEvent test hook --- .../{test.integration.ts => hooks/useAgile.ts} | 16 ++++++++-------- src/integrations/test/hooks/useEvent.ts | 18 ++++++++++++++++++ src/integrations/test/index.ts | 2 ++ .../functions/collect.function.spec.ts | 6 +++--- .../functions/remove.function.spec.ts | 6 +++--- .../functions/update.function.spec.ts | 4 ++-- test/collection/group/default.spec.ts | 6 +++--- .../group/functions/add.function.spec.ts | 4 ++-- .../group/functions/remove.function.spec.ts | 4 ++-- test/collection/selector/default.spec.ts | 4 ++-- .../selector/functions/select.function.spec.ts | 4 ++-- test/computed/{default.ts => default.spec.ts} | 6 +++--- .../updateComputeFunction.function.spec.ts | 4 ++-- test/state/functions/patch.function.spec.ts | 4 ++-- test/state/functions/reset.function.spec.ts | 4 ++-- test/state/functions/set.function.spec.ts | 4 ++-- test/state/functions/undo.function.spec.ts | 4 ++-- 17 files changed, 60 insertions(+), 40 deletions(-) rename src/integrations/test/{test.integration.ts => hooks/useAgile.ts} (74%) create mode 100644 src/integrations/test/hooks/useEvent.ts create mode 100644 src/integrations/test/index.ts rename test/computed/{default.ts => default.spec.ts} (97%) diff --git a/src/integrations/test/test.integration.ts b/src/integrations/test/hooks/useAgile.ts similarity index 74% rename from src/integrations/test/test.integration.ts rename to src/integrations/test/hooks/useAgile.ts index c1bfd509..a2ea0c2e 100644 --- a/src/integrations/test/test.integration.ts +++ b/src/integrations/test/hooks/useAgile.ts @@ -1,8 +1,8 @@ -import State from "../../state"; -import Collection from "../../collection"; -import Agile from "../../index"; -import {getAgileInstance, normalizeArray} from "../../utils"; -import Group from "../../collection/group"; +import State from "../../../state"; +import Collection from "../../../collection"; +import Agile from "../../../index"; +import {getAgileInstance, normalizeArray} from "../../../utils"; +import Group from "../../../collection/group"; //========================================================================================================= @@ -28,12 +28,12 @@ type AgileHookType = T extends Group ? U[] : never; // Array -export function useTest>(deps: X, callBackFunction: Function, agileInstance?: Agile): AgileHookArrayType; +export function useAgile>(deps: X, callBackFunction: Function, agileInstance?: Agile): AgileHookArrayType; // No Array -export function useTest(deps: X, callBackFunction: Function, agileInstance?: Agile): AgileHookType; +export function useAgile(deps: X, callBackFunction: Function, agileInstance?: Agile): AgileHookType; -export function useTest, Y extends State | Collection | undefined>(deps: X | Y, callBackFunction: Function, agileInstance?: Agile): AgileHookArrayType | AgileHookType { +export function useAgile, Y extends State | Collection | undefined>(deps: X | Y, callBackFunction: Function, agileInstance?: Agile): AgileHookArrayType | AgileHookType { // Normalize Dependencies let depsArray = normalizeArray(deps) .map(item => item instanceof Collection ? item.getGroup(item.config.defaultGroupKey || 'default') : item) diff --git a/src/integrations/test/hooks/useEvent.ts b/src/integrations/test/hooks/useEvent.ts new file mode 100644 index 00000000..513ea7c7 --- /dev/null +++ b/src/integrations/test/hooks/useEvent.ts @@ -0,0 +1,18 @@ +import Event, {EventCallbackFunction} from "../../../event"; +import Agile from "../../../index"; +import {getAgileInstance} from "../../../utils"; + +export function useEvent(event: E, callback: EventCallbackFunction, agileInstance?: Agile) { + // Get Agile Instance + if (!agileInstance) { + const tempAgileInstance = getAgileInstance(event); + if (!tempAgileInstance) { + console.error("Agile: Failed to get Agile Instance"); + return; + } + agileInstance = tempAgileInstance; + } + + // Call on Event + event.on(callback); +} diff --git a/src/integrations/test/index.ts b/src/integrations/test/index.ts new file mode 100644 index 00000000..2f96a5ec --- /dev/null +++ b/src/integrations/test/index.ts @@ -0,0 +1,2 @@ +export {useAgile} from './hooks/useAgile'; +export {useEvent} from './hooks/useEvent'; diff --git a/test/collection/functions/collect.function.spec.ts b/test/collection/functions/collect.function.spec.ts index 85a507c4..6c9d47bc 100644 --- a/test/collection/functions/collect.function.spec.ts +++ b/test/collection/functions/collect.function.spec.ts @@ -1,7 +1,7 @@ import 'mocha'; import {expect} from 'chai'; import Agile from "../../../src"; -import {useTest} from "../../../src/integrations/test/test.integration"; +import {useAgile} from "../../../src/integrations/test"; import Group from "../../../src/collection/group"; describe('Collect Function Tests', () => { @@ -31,7 +31,7 @@ describe('Collect Function Tests', () => { const MY_COLLECTION = App.Collection(); // Set 'Hook' for testing the rerenderFunctionality with the callbackFunction (Note: the value of myHookState doesn't get changed because no rerenders happen -> no reassign of the value) - const [myHookCollection] = useTest([MY_COLLECTION], () => { + const [myHookCollection] = useAgile([MY_COLLECTION], () => { rerenderCount++; }); @@ -314,7 +314,7 @@ describe('Collect Function Tests', () => { }); // Set 'Hook' for testing the rerenderFunctionality with the callbackFunction (Note: the value of myHookState doesn't get changed because no rerenders happen -> no reassign of the value) - const [myHookCollection] = useTest([MY_COLLECTION], () => { + const [myHookCollection] = useAgile([MY_COLLECTION], () => { rerenderCount++; }); diff --git a/test/collection/functions/remove.function.spec.ts b/test/collection/functions/remove.function.spec.ts index 59ce702b..75e12a70 100644 --- a/test/collection/functions/remove.function.spec.ts +++ b/test/collection/functions/remove.function.spec.ts @@ -1,7 +1,7 @@ import 'mocha'; import {expect} from 'chai'; import Agile from "../../../src"; -import {useTest} from "../../../src/integrations/test/test.integration"; +import {useAgile} from "../../../src/integrations/test"; import Item from "../../../src/collection/item"; describe('Remove Function Tests', () => { @@ -36,7 +36,7 @@ describe('Remove Function Tests', () => { ); // Set 'Hook' for testing the rerenderFunctionality with the callbackFunction (Note: the value of myHookState doesn't get changed because no rerenders happen -> no reassign of the value) - const [myGroup1, myGroup2] = useTest([MY_COLLECTION.getGroup('group1'), MY_COLLECTION.getGroup('group2')], () => { + const [myGroup1, myGroup2] = useAgile([MY_COLLECTION.getGroup('group1'), MY_COLLECTION.getGroup('group2')], () => { rerenderCount++; }); @@ -152,7 +152,7 @@ describe('Remove Function Tests', () => { ); // Set 'Hook' for testing the rerenderFunctionality with the callbackFunction (Note: the value of myHookState doesn't get changed because no rerenders happen -> no reassign of the value) - const [myGroup1, myGroup2] = useTest([MY_COLLECTION.getGroup('group1'), MY_COLLECTION.getGroup('group2')], () => { + const [myGroup1, myGroup2] = useAgile([MY_COLLECTION.getGroup('group1'), MY_COLLECTION.getGroup('group2')], () => { rerenderCount++; }); diff --git a/test/collection/functions/update.function.spec.ts b/test/collection/functions/update.function.spec.ts index 2c208a13..a57986c3 100644 --- a/test/collection/functions/update.function.spec.ts +++ b/test/collection/functions/update.function.spec.ts @@ -1,7 +1,7 @@ import 'mocha'; import {expect} from 'chai'; import Agile from "../../../src"; -import {useTest} from "../../../src/integrations/test/test.integration"; +import {useAgile} from "../../../src/integrations/test"; import Group from "../../../src/collection/group"; describe('Update Function Tests', () => { @@ -30,7 +30,7 @@ describe('Update Function Tests', () => { const MY_COLLECTION = App.Collection(); // Set 'Hook' for testing the rerenderFunctionality with the callbackFunction (Note: the value of myHookState doesn't get changed because no rerenders happen -> no reassign of the value) - const [myHookCollection] = useTest([MY_COLLECTION], () => { + const [myHookCollection] = useAgile([MY_COLLECTION], () => { rerenderCount++; }); diff --git a/test/collection/group/default.spec.ts b/test/collection/group/default.spec.ts index e8527e04..0648464c 100644 --- a/test/collection/group/default.spec.ts +++ b/test/collection/group/default.spec.ts @@ -1,5 +1,5 @@ import Agile from "../../../src"; -import {useTest} from "../../../src/integrations/test/test.integration"; +import {useAgile} from "../../../src/integrations/test"; import {expect} from "chai"; import Group from "../../../src/collection/group"; @@ -34,7 +34,7 @@ describe('Default Group Tests', () => { ); // Set 'Hook' for testing the rerenderFunctionality with the callbackFunction (Note: the value of myHookState doesn't get changed because no rerenders happen -> no reassign of the value) - const [myGroup1] = useTest([MY_COLLECTION.getGroup('group1')], () => { + const [myGroup1] = useAgile([MY_COLLECTION.getGroup('group1')], () => { rerenderCount++; }); @@ -102,7 +102,7 @@ describe('Default Group Tests', () => { ); // Set 'Hook' for testing the rerenderFunctionality with the callbackFunction (Note: the value of myHookState doesn't get changed because no rerenders happen -> no reassign of the value) - const [myGroup1] = useTest([MY_COLLECTION.getGroup('group1')], () => { + const [myGroup1] = useAgile([MY_COLLECTION.getGroup('group1')], () => { rerenderCount++; }); diff --git a/test/collection/group/functions/add.function.spec.ts b/test/collection/group/functions/add.function.spec.ts index 8c11079a..0db013f6 100644 --- a/test/collection/group/functions/add.function.spec.ts +++ b/test/collection/group/functions/add.function.spec.ts @@ -1,5 +1,5 @@ import Agile from "../../../../src"; -import {useTest} from "../../../../src/integrations/test/test.integration"; +import {useAgile} from "../../../../src/integrations/test"; import {expect} from "chai"; import Group from "../../../../src/collection/group"; @@ -33,7 +33,7 @@ describe('Add function Tests', () => { ); // Set 'Hook' for testing the rerenderFunctionality with the callbackFunction (Note: the value of myHookState doesn't get changed because no rerenders happen -> no reassign of the value) - const [myGroup1] = useTest([MY_COLLECTION.getGroup('group1')], () => { + const [myGroup1] = useAgile([MY_COLLECTION.getGroup('group1')], () => { rerenderCount++; }); diff --git a/test/collection/group/functions/remove.function.spec.ts b/test/collection/group/functions/remove.function.spec.ts index aa9cc7a7..b09478b1 100644 --- a/test/collection/group/functions/remove.function.spec.ts +++ b/test/collection/group/functions/remove.function.spec.ts @@ -1,5 +1,5 @@ import Agile from "../../../../src"; -import {useTest} from "../../../../src/integrations/test/test.integration"; +import {useAgile} from "../../../../src/integrations/test"; import {expect} from "chai"; import Group from "../../../../src/collection/group"; @@ -33,7 +33,7 @@ describe('Add function Tests', () => { ); // Set 'Hook' for testing the rerenderFunctionality with the callbackFunction (Note: the value of myHookState doesn't get changed because no rerenders happen -> no reassign of the value) - const [myGroup1] = useTest([MY_COLLECTION.getGroup('group1')], () => { + const [myGroup1] = useAgile([MY_COLLECTION.getGroup('group1')], () => { rerenderCount++; }); diff --git a/test/collection/selector/default.spec.ts b/test/collection/selector/default.spec.ts index 7d0734d0..44eceaa8 100644 --- a/test/collection/selector/default.spec.ts +++ b/test/collection/selector/default.spec.ts @@ -1,5 +1,5 @@ import Agile from "../../../src"; -import {useTest} from "../../../src/integrations/test/test.integration"; +import {useAgile} from "../../../src/integrations/test"; import {expect} from "chai"; import Selector from "../../../src/collection/selector"; import Item from "../../../src/collection/item"; @@ -35,7 +35,7 @@ describe('Default Selector Tests', () => { ); // Set 'Hook' for testing the rerenderFunctionality with the callbackFunction (Note: the value of myHookState doesn't get changed because no rerenders happen -> no reassign of the value) - const [mySelector1] = useTest([MY_COLLECTION.getSelector('selector1')], () => { + const [mySelector1] = useAgile([MY_COLLECTION.getSelector('selector1')], () => { rerenderCount++; }); diff --git a/test/collection/selector/functions/select.function.spec.ts b/test/collection/selector/functions/select.function.spec.ts index 2e79e823..d572eb22 100644 --- a/test/collection/selector/functions/select.function.spec.ts +++ b/test/collection/selector/functions/select.function.spec.ts @@ -1,5 +1,5 @@ import Agile from "../../../../src"; -import {useTest} from "../../../../src/integrations/test/test.integration"; +import {useAgile} from "../../../../src/integrations/test"; import {expect} from "chai"; import Selector from "../../../../src/collection/selector"; import Item from "../../../../src/collection/item"; @@ -34,7 +34,7 @@ describe('select Function Tests', () => { ); // Set 'Hook' for testing the rerenderFunctionality with the callbackFunction (Note: the value of myHookState doesn't get changed because no rerenders happen -> no reassign of the value) - const [mySelector1] = useTest([MY_COLLECTION.getSelector('selector1')], () => { + const [mySelector1] = useAgile([MY_COLLECTION.getSelector('selector1')], () => { rerenderCount++; }); diff --git a/test/computed/default.ts b/test/computed/default.spec.ts similarity index 97% rename from test/computed/default.ts rename to test/computed/default.spec.ts index 3ae5b5ae..66fa7049 100644 --- a/test/computed/default.ts +++ b/test/computed/default.spec.ts @@ -2,7 +2,7 @@ import 'mocha'; import {expect} from 'chai'; import Agile from "../../src"; import Computed from "../../src/computed"; -import {useTest} from "../../src/integrations/test/test.integration"; +import {useAgile} from "../../src/integrations/test"; describe('Default Computed Tests', () => { // Define Agile @@ -48,7 +48,7 @@ describe('Default Computed Tests', () => { }); // Set 'Hook' for testing the rerenderFunctionality with the callbackFunction (Note: the value of myHookState doesn't get changed because no rerenders happen -> no reassign of the value) - const [myComputed] = useTest([MY_COMPUTED], () => { + const [myComputed] = useAgile([MY_COMPUTED], () => { rerenderCount++; }); @@ -122,7 +122,7 @@ describe('Default Computed Tests', () => { }, [MY_STATE_3]); // Set 'Hook' for testing the rerenderFunctionality with the callbackFunction (Note: the value of myHookState doesn't get changed because no rerenders happen -> no reassign of the value) - const [myComputed] = useTest([MY_COMPUTED], () => { + const [myComputed] = useAgile([MY_COMPUTED], () => { rerenderCount++; }); diff --git a/test/computed/functions/updateComputeFunction.function.spec.ts b/test/computed/functions/updateComputeFunction.function.spec.ts index 41c9c900..d8140da3 100644 --- a/test/computed/functions/updateComputeFunction.function.spec.ts +++ b/test/computed/functions/updateComputeFunction.function.spec.ts @@ -2,7 +2,7 @@ import 'mocha'; import {expect} from 'chai'; import Agile from "../../../src"; import Computed from "../../../src/computed"; -import {useTest} from "../../../src/integrations/test/test.integration"; +import {useAgile} from "../../../src/integrations/test"; describe('updateComputeFunction Function tests', () => { let rerenderCount = 0; @@ -31,7 +31,7 @@ describe('updateComputeFunction Function tests', () => { }); // Set 'Hook' for testing the rerenderFunctionality with the callbackFunction (Note: the value of myHookState doesn't get changed because no rerenders happen -> no reassign of the value) - const [myComputed] = useTest([MY_COMPUTED], () => { + const [myComputed] = useAgile([MY_COMPUTED], () => { rerenderCount++; }); diff --git a/test/state/functions/patch.function.spec.ts b/test/state/functions/patch.function.spec.ts index 9aa14a91..f01eec2f 100644 --- a/test/state/functions/patch.function.spec.ts +++ b/test/state/functions/patch.function.spec.ts @@ -1,7 +1,7 @@ import 'mocha'; import {expect} from 'chai'; import Agile from "../../../src"; -import {useTest} from "../../../src/integrations/test/test.integration"; +import {useAgile} from "../../../src/integrations/test"; describe('Patch Function Tests', () => { let rerenderCount = 0; @@ -34,7 +34,7 @@ describe('Patch Function Tests', () => { }; // Set 'Hook' for testing the rerenderFunctionality with the callbackFunction (Note: the value of myHookState doesn't get changed because no rerenders happen -> no reassign of the value) - const [myHookState] = useTest([MY_STATE], () => { + const [myHookState] = useAgile([MY_STATE], () => { rerenderCount++; }); diff --git a/test/state/functions/reset.function.spec.ts b/test/state/functions/reset.function.spec.ts index f46f52fe..932afe4d 100644 --- a/test/state/functions/reset.function.spec.ts +++ b/test/state/functions/reset.function.spec.ts @@ -1,7 +1,7 @@ import 'mocha'; import {expect} from 'chai'; import Agile from "../../../src"; -import {useTest} from "../../../src/integrations/test/test.integration"; +import {useAgile} from "../../../src/integrations/test"; describe('Reset Function Tests', () => { let rerenderCount = 0; @@ -28,7 +28,7 @@ describe('Reset Function Tests', () => { }; // Set 'Hook' for testing the rerenderFunctionality with the callbackFunction (Note: the value of myHookState doesn't get changed because no rerenders happen -> no reassign of the value) - const [myHookState] = useTest([MY_STATE], () => { + const [myHookState] = useAgile([MY_STATE], () => { rerenderCount++; }); diff --git a/test/state/functions/set.function.spec.ts b/test/state/functions/set.function.spec.ts index d3476a2f..4f2bc23e 100644 --- a/test/state/functions/set.function.spec.ts +++ b/test/state/functions/set.function.spec.ts @@ -1,7 +1,7 @@ import 'mocha'; import {expect} from 'chai'; import Agile from "../../../src"; -import {useTest} from "../../../src/integrations/test/test.integration"; +import {useAgile} from "../../../src/integrations/test"; describe('Set Function Tests', () => { let rerenderCount = 0; @@ -28,7 +28,7 @@ describe('Set Function Tests', () => { }; // Set 'Hook' for testing the rerenderFunctionality with the callbackFunction (Note: the value of myHookState doesn't get changed because no rerenders happen -> no reassign of the value) - const [myHookState] = useTest([MY_STATE], () => { + const [myHookState] = useAgile([MY_STATE], () => { rerenderCount++; }); diff --git a/test/state/functions/undo.function.spec.ts b/test/state/functions/undo.function.spec.ts index 7792d974..27ffb3f9 100644 --- a/test/state/functions/undo.function.spec.ts +++ b/test/state/functions/undo.function.spec.ts @@ -1,7 +1,7 @@ import 'mocha'; import {expect} from 'chai'; import Agile from "../../../src"; -import {useTest} from "../../../src/integrations/test/test.integration"; +import {useAgile} from "../../../src/integrations/test"; describe('Undo Function Tests', () => { let rerenderCount = 0; @@ -28,7 +28,7 @@ describe('Undo Function Tests', () => { }; // Set 'Hook' for testing the rerenderFunctionality with the callbackFunction (Note: the value of myHookState doesn't get changed because no rerenders happen -> no reassign of the value) - const [myHookState] = useTest([MY_STATE], () => { + const [myHookState] = useAgile([MY_STATE], () => { rerenderCount++; }); From 8efcbc7dbe1fba519dfad9e0e7de8485bc0ea23c Mon Sep 17 00:00:00 2001 From: Benno Kohrs Date: Sat, 12 Sep 2020 15:55:47 +0200 Subject: [PATCH 11/25] Removed unnecessary interfaces --- test/collection/default.spec.ts | 45 ++++----------------------------- 1 file changed, 5 insertions(+), 40 deletions(-) diff --git a/test/collection/default.spec.ts b/test/collection/default.spec.ts index 9ccc54ad..fed28f60 100644 --- a/test/collection/default.spec.ts +++ b/test/collection/default.spec.ts @@ -8,12 +8,12 @@ describe('Default Collection Tests', () => { // Define Agile const App = new Agile(); - describe('Collection', () => { - interface userInterface { - id: number - name: string - } + interface userInterface { + id: number + name: string + } + describe('Collection', () => { // Set Collections const MY_COLLECTION = App.Collection(); @@ -43,11 +43,6 @@ describe('Default Collection Tests', () => { }); describe('Collection with Key', () => { - interface userInterface { - id: number - name: string - } - // Set Collection const MY_COLLECTION = App.Collection({ key: 'myCollectionKey' @@ -69,11 +64,6 @@ describe('Default Collection Tests', () => { describe('Collection with default Groups', () => { describe('Default Groups in Array shape', () => { - interface userInterface { - id: number - name: string - } - // Set Collection const MY_COLLECTION = App.Collection({ groups: ['group1', 'group2'] @@ -111,11 +101,6 @@ describe('Default Collection Tests', () => { }); describe('Collection with Key', () => { - interface userInterface { - id: number - name: string - } - // Set Collection const MY_COLLECTION = App.Collection({ key: 'myCollectionKey' @@ -137,11 +122,6 @@ describe('Default Collection Tests', () => { describe('Collection with default Selectors', () => { describe('Default Selector in Array shape', () => { - interface userInterface { - id: number - name: string - } - // Set Collection const MY_COLLECTION = App.Collection({ selectors: ['selector1', 'selector2'] @@ -156,11 +136,6 @@ describe('Default Collection Tests', () => { }); describe('Default Selectors in Object shape', () => { - interface userInterface { - id: number - name: string - } - // Set Collection const MY_COLLECTION = App.Collection((collection) => ({ selectors: { @@ -179,11 +154,6 @@ describe('Default Collection Tests', () => { }); describe('Collection with primaryKey', () => { - interface userInterface { - key: number - name: string - } - // Set Collection const MY_COLLECTION = App.Collection({ primaryKey: 'key' @@ -195,11 +165,6 @@ describe('Default Collection Tests', () => { }); describe('Collection with defaultGroupKey', () => { - interface userInterface { - id: number - name: string - } - // Set Collection const MY_COLLECTION = App.Collection({ defaultGroupKey: 'normal' From 002fb0d2a51ee048f484ca67f370ef50c2abe6b7 Mon Sep 17 00:00:00 2001 From: Benno Kohrs Date: Sat, 12 Sep 2020 16:05:39 +0200 Subject: [PATCH 12/25] Added event key --- src/collection/index.ts | 4 ++-- src/event/index.ts | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/collection/index.ts b/src/collection/index.ts index 77e743f0..ae61b3d1 100644 --- a/src/collection/index.ts +++ b/src/collection/index.ts @@ -61,10 +61,10 @@ export default class Collection { // Set Key this._key = this.config.key; - // Create Groups + // Init Groups this.initSubInstances('groups'); - // Create Selectors + // Init Selectors this.initSubInstances('selectors'); } diff --git a/src/event/index.ts b/src/event/index.ts index 054c10b0..3163c31f 100644 --- a/src/event/index.ts +++ b/src/event/index.ts @@ -1,5 +1,6 @@ import Agile from "../agile"; import {defineConfig} from "../utils"; +import {StateKey} from "../state"; export type DefaultEventPayload = { [key: string]: any }; export type EventCallbackFunction = (payload?: PayloadType) => void; @@ -17,6 +18,7 @@ export default class Event { public config: EventConfig; + public _key?: StateKey; // should be a unique key/name which identifies the event private callbacks: Set> = new Set(); // Stores callback functions public uses: number = 0; // How often the event has been used private currentTimeout: any; // The current timeout (function) @@ -32,6 +34,17 @@ export default class Event { this.config = defineConfig(config, { enabled: true }); + + // Set Key + this._key = this.config.key; + } + + public set key(value: StateKey | undefined) { + this._key = value; + } + + public get key(): StateKey | undefined { + return this._key; } From 6b00dd0d38c6094e07f37bf0d1f306b8aa4cc1d7 Mon Sep 17 00:00:00 2001 From: Benno Kohrs Date: Sat, 12 Sep 2020 17:52:40 +0200 Subject: [PATCH 13/25] Made event callbacks public --- src/event/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/event/index.ts b/src/event/index.ts index 3163c31f..2b605258 100644 --- a/src/event/index.ts +++ b/src/event/index.ts @@ -19,7 +19,7 @@ export default class Event { public config: EventConfig; public _key?: StateKey; // should be a unique key/name which identifies the event - private callbacks: Set> = new Set(); // Stores callback functions + public callbacks: Set> = new Set(); // Stores callback functions public uses: number = 0; // How often the event has been used private currentTimeout: any; // The current timeout (function) private queue: Array = []; // Queue if something is currently in timeout From 5609da3b245dc6050b20b522b752bb038b04e43f Mon Sep 17 00:00:00 2001 From: Benno Kohrs Date: Sat, 12 Sep 2020 17:54:49 +0200 Subject: [PATCH 14/25] Created event default tests --- test/collection/default.spec.ts | 6 +-- test/event/default.spec.ts | 88 +++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 test/event/default.spec.ts diff --git a/test/collection/default.spec.ts b/test/collection/default.spec.ts index fed28f60..84b1ea07 100644 --- a/test/collection/default.spec.ts +++ b/test/collection/default.spec.ts @@ -35,10 +35,10 @@ describe('Default Collection Tests', () => { it('Can change key', () => { // Update key - MY_COLLECTION.key = 'withKey'; + MY_COLLECTION.key = 'myKey'; - expect(MY_COLLECTION.key).to.eq('withKey', 'MY_STATE has correct key'); - expect(MY_COLLECTION._key).to.eq('withKey', 'My_STATE has correct _key'); + expect(MY_COLLECTION.key).to.eq('myKey', 'MY_COLLECTION has correct key'); + expect(MY_COLLECTION._key).to.eq('myKey', 'MY_COLLECTION has correct _key'); }); }); diff --git a/test/event/default.spec.ts b/test/event/default.spec.ts new file mode 100644 index 00000000..f960d4f5 --- /dev/null +++ b/test/event/default.spec.ts @@ -0,0 +1,88 @@ +import 'mocha'; +import {expect} from 'chai'; +import Agile from "../../src"; + +describe('Default Event Tests', () => { + // Define Agile + const App = new Agile(); + + interface EventPayload { + title: string + message: string + } + + describe('Event', () => { + // Create Event + const MY_EVENT = App.Event(); + + it('Has correct initial value', () => { + expect(MY_EVENT.uses).to.eq(0, 'MY_EVENT uses has correct initial value'); + expect(JSON.stringify(MY_EVENT.config)).to.eq(JSON.stringify({enabled: true}), 'MY_EVENT has correct initial config'); + expect(MY_EVENT.callbacks.size).to.eq(0, 'MY_EVENT has correct initial callback size'); + expect(MY_EVENT.key).to.eq(undefined, 'MY_EVENT has correct key'); + expect(MY_EVENT._key).to.eq(undefined, 'MY_EVENT has correct _key'); + }); + + it('Can change key', () => { + // Update key + MY_EVENT.key = 'myKey'; + + expect(MY_EVENT.key).to.eq('myKey', 'MY_EVENT has correct key'); + expect(MY_EVENT._key).to.eq('myKey', 'MY_EVENT has correct _key'); + }); + }); + + describe('Event with key', () => { + // Create Event + const MY_EVENT = App.Event({key: 'myKey'}); + + it('Has correct initial value', () => { + expect(MY_EVENT.uses).to.eq(0, 'MY_EVENT uses has correct initial value'); + expect(JSON.stringify(MY_EVENT.config)).to.eq(JSON.stringify({enabled: true, key: 'myKey'}), 'MY_EVENT has correct initial config'); + expect(MY_EVENT.callbacks.size).to.eq(0, 'MY_EVENT has correct initial callback size'); + expect(MY_EVENT.key).to.eq('myKey', 'MY_EVENT has correct key'); + expect(MY_EVENT._key).to.eq('myKey', 'MY_EVENT has correct _key'); + }); + + it('Can change key', () => { + // Update key + MY_EVENT.key = 'myNewKey'; + + expect(MY_EVENT.key).to.eq('myNewKey', 'MY_EVENT has correct key'); + expect(MY_EVENT._key).to.eq('myNewKey', 'MY_EVENT has correct _key'); + }); + }); + + describe('Event with enabled = false', () => { + // Create Event + const MY_EVENT = App.Event({enabled: false}); + + it('Has correct initial value', () => { + expect(MY_EVENT.uses).to.eq(0, 'MY_EVENT uses has correct initial value'); + expect(JSON.stringify(MY_EVENT.config)).to.eq(JSON.stringify({enabled: false}), 'MY_EVENT has correct initial config'); + expect(MY_EVENT.callbacks.size).to.eq(0, 'MY_EVENT has correct initial callback size'); + }); + }); + + describe('Event with delay', () => { + // Create Event + const MY_EVENT = App.Event({delay: 1000}); + + it('Has correct initial value', () => { + expect(MY_EVENT.uses).to.eq(0, 'MY_EVENT uses has correct initial value'); + expect(JSON.stringify(MY_EVENT.config)).to.eq(JSON.stringify({enabled: true, delay: 1000}), 'MY_EVENT has correct initial config'); + expect(MY_EVENT.callbacks.size).to.eq(0, 'MY_EVENT has correct initial callback size'); + }); + }); + + describe('Event with maxUses', () => { + // Create Event + const MY_EVENT = App.Event({maxUses: 10}); + + it('Has correct initial value', () => { + expect(MY_EVENT.uses).to.eq(0, 'MY_EVENT uses has correct initial value'); + expect(JSON.stringify(MY_EVENT.config)).to.eq(JSON.stringify({enabled: true, maxUses: 10}), 'MY_EVENT has correct initial config'); + expect(MY_EVENT.callbacks.size).to.eq(0, 'MY_EVENT has correct initial callback size'); + }); + }); +}); From 6d93075a66a01e2d44ef4dd55c2cfcfec9ebabac Mon Sep 17 00:00:00 2001 From: Benno Kohrs Date: Sat, 12 Sep 2020 20:46:51 +0200 Subject: [PATCH 15/25] Added enabled as public variable in event --- src/event/index.ts | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/event/index.ts b/src/event/index.ts index 2b605258..9ae46658 100644 --- a/src/event/index.ts +++ b/src/event/index.ts @@ -23,6 +23,7 @@ export default class Event { public uses: number = 0; // How often the event has been used private currentTimeout: any; // The current timeout (function) private queue: Array = []; // Queue if something is currently in timeout + public enabled: boolean = true; // @ts-ignore public payload: PayloadType; // Only holds reference to the PayloadType so that it can be read external (never defined) @@ -37,6 +38,10 @@ export default class Event { // Set Key this._key = this.config.key; + + // Set Enabled + if (this.config.enabled !== undefined) + this.enabled = this.config.enabled; } public set key(value: StateKey | undefined) { @@ -57,13 +62,6 @@ export default class Event { public on(callback: EventCallbackFunction) { const cleanUpFunction = () => this.unsub(callback); - if (this.config.maxUses && this.uses > this.config.maxUses) { - // Disable Event - this.disable(); - - return cleanUpFunction; - } - // Add callback to Event Callbacks this.callbacks.add(callback); @@ -79,7 +77,7 @@ export default class Event { */ public trigger(payload?: PayloadType) { // If event is disabled, return - if (!this.config.enabled) return this; + if (!this.enabled) return this; if (this.config.delay) this.delayedTrigger(payload); @@ -97,7 +95,7 @@ export default class Event { * Disables the Event */ public disable() { - this.config.enabled = false; + this.enabled = false; return this; } @@ -108,7 +106,7 @@ export default class Event { * Enables the Event */ public enable() { - this.config.enabled = true; + this.enabled = true; return this; } @@ -120,8 +118,8 @@ export default class Event { * Resets the Event */ public reset() { - // Enable event - this.enable(); + // Set Enabled + this.enabled = this.config.enabled || true; // Reset Uses this.uses = 0; @@ -157,6 +155,11 @@ export default class Event { // Increase uses this.uses++; + + // Check if maxUses has been reached, if so disable event + if (this.config.maxUses && this.uses >= this.config.maxUses) + // Disable Event + this.disable(); } From badf7607b50daff1479b4eaf709f7b48c52afcc8 Mon Sep 17 00:00:00 2001 From: Benno Kohrs Date: Sat, 12 Sep 2020 20:47:14 +0200 Subject: [PATCH 16/25] Optimized default event tests --- test/event/default.spec.ts | 113 +++++++++++++++++++++++++++++++++++-- 1 file changed, 108 insertions(+), 5 deletions(-) diff --git a/test/event/default.spec.ts b/test/event/default.spec.ts index f960d4f5..4154441f 100644 --- a/test/event/default.spec.ts +++ b/test/event/default.spec.ts @@ -19,6 +19,7 @@ describe('Default Event Tests', () => { expect(MY_EVENT.uses).to.eq(0, 'MY_EVENT uses has correct initial value'); expect(JSON.stringify(MY_EVENT.config)).to.eq(JSON.stringify({enabled: true}), 'MY_EVENT has correct initial config'); expect(MY_EVENT.callbacks.size).to.eq(0, 'MY_EVENT has correct initial callback size'); + expect(MY_EVENT.enabled).to.eq(true, 'MY_EVENT is enabled'); expect(MY_EVENT.key).to.eq(undefined, 'MY_EVENT has correct key'); expect(MY_EVENT._key).to.eq(undefined, 'MY_EVENT has correct _key'); }); @@ -40,6 +41,7 @@ describe('Default Event Tests', () => { expect(MY_EVENT.uses).to.eq(0, 'MY_EVENT uses has correct initial value'); expect(JSON.stringify(MY_EVENT.config)).to.eq(JSON.stringify({enabled: true, key: 'myKey'}), 'MY_EVENT has correct initial config'); expect(MY_EVENT.callbacks.size).to.eq(0, 'MY_EVENT has correct initial callback size'); + expect(MY_EVENT.enabled).to.eq(true, 'MY_EVENT is enabled'); expect(MY_EVENT.key).to.eq('myKey', 'MY_EVENT has correct key'); expect(MY_EVENT._key).to.eq('myKey', 'MY_EVENT has correct _key'); }); @@ -54,35 +56,136 @@ describe('Default Event Tests', () => { }); describe('Event with enabled = false', () => { + let eventCallCount = 0; + let currentEventPayload; + // Create Event const MY_EVENT = App.Event({enabled: false}); + MY_EVENT.on((payload) => { + eventCallCount++; + currentEventPayload = payload; + }); + it('Has correct initial value', () => { expect(MY_EVENT.uses).to.eq(0, 'MY_EVENT uses has correct initial value'); expect(JSON.stringify(MY_EVENT.config)).to.eq(JSON.stringify({enabled: false}), 'MY_EVENT has correct initial config'); - expect(MY_EVENT.callbacks.size).to.eq(0, 'MY_EVENT has correct initial callback size'); + expect(MY_EVENT.callbacks.size).to.eq(1, 'MY_EVENT has correct initial callback size'); + expect(MY_EVENT.enabled).to.eq(false, 'MY_EVENT is disabled'); + + expect(eventCallCount).to.eq(0, 'eventCallCount has correct initial value'); + expect(currentEventPayload).to.eq(undefined, 'currentEventPayload has correct initial value'); + }); + + it('Doesn\'t call event callbacks', () => { + // Trigger Event + MY_EVENT.trigger({title: 'test', message: 'messageTest'}); + + expect(MY_EVENT.uses).to.eq(0, 'MY_EVENT uses stayed the same'); + expect(MY_EVENT.enabled).to.eq(false, 'MY_EVENT is disabled'); + + expect(eventCallCount).to.eq(0, 'eventCallCount stayed the same'); + expect(currentEventPayload).to.eq(undefined, 'currentEventPayload stayed the same'); }); }); describe('Event with delay', () => { + let eventCallCount = 0; + let currentEventPayload; + // Create Event const MY_EVENT = App.Event({delay: 1000}); + MY_EVENT.on((payload) => { + eventCallCount++; + currentEventPayload = payload; + }); + it('Has correct initial value', () => { expect(MY_EVENT.uses).to.eq(0, 'MY_EVENT uses has correct initial value'); expect(JSON.stringify(MY_EVENT.config)).to.eq(JSON.stringify({enabled: true, delay: 1000}), 'MY_EVENT has correct initial config'); - expect(MY_EVENT.callbacks.size).to.eq(0, 'MY_EVENT has correct initial callback size'); + expect(MY_EVENT.callbacks.size).to.eq(1, 'MY_EVENT has correct initial callback size'); + expect(MY_EVENT.enabled).to.eq(true, 'MY_EVENT is enabled'); + + expect(eventCallCount).to.eq(0, 'eventCallCount has correct initial value'); + expect(currentEventPayload).to.eq(undefined, 'currentEventPayload has correct initial value'); + }); + + it('Does call callbacks with delay', async () => { + // Trigger Event + MY_EVENT.trigger({title: 'test', message: 'messageTest'}); + + expect(MY_EVENT.uses).to.eq(0, 'MY_EVENT uses stayed the same'); + expect(MY_EVENT.enabled).to.eq(true, 'MY_EVENT is enabled'); + + expect(eventCallCount).to.eq(0, 'eventCallCount stayed the same'); + expect(currentEventPayload).to.eq(undefined, 'currentEventPayload stayed the same'); + + // Wait one second + await new Promise(resolve => setTimeout(resolve, 1000)); + + expect(MY_EVENT.uses).to.eq(1, 'MY_EVENT uses has been increased by 1'); + expect(MY_EVENT.enabled).to.eq(true, 'MY_EVENT is enabled'); + + expect(eventCallCount).to.eq(1, 'eventCallCount has been increased by 1'); + expect(JSON.stringify(currentEventPayload)).to.eq(JSON.stringify({title: 'test', message: 'messageTest'}), 'currentEventPayload has the correct value'); }); }); describe('Event with maxUses', () => { + let eventCallCount = 0; + let currentEventPayload; + // Create Event - const MY_EVENT = App.Event({maxUses: 10}); + const MY_EVENT = App.Event({maxUses: 3}); + + MY_EVENT.on((payload) => { + eventCallCount++; + currentEventPayload = payload; + }); it('Has correct initial value', () => { expect(MY_EVENT.uses).to.eq(0, 'MY_EVENT uses has correct initial value'); - expect(JSON.stringify(MY_EVENT.config)).to.eq(JSON.stringify({enabled: true, maxUses: 10}), 'MY_EVENT has correct initial config'); - expect(MY_EVENT.callbacks.size).to.eq(0, 'MY_EVENT has correct initial callback size'); + expect(JSON.stringify(MY_EVENT.config)).to.eq(JSON.stringify({enabled: true, maxUses: 3}), 'MY_EVENT has correct initial config'); + expect(MY_EVENT.callbacks.size).to.eq(1, 'MY_EVENT has correct initial callback size'); + expect(MY_EVENT.enabled).to.eq(true, 'MY_EVENT is enabled'); + + expect(eventCallCount).to.eq(0, 'eventCallCount has correct initial value'); + expect(currentEventPayload).to.eq(undefined, 'currentEventPayload has correct initial value'); + }); + + it('Get disabled after 3 uses', () => { + // Trigger Event + MY_EVENT.trigger({title: 'test', message: 'messageTest'}); + + expect(MY_EVENT.enabled).to.eq(true, 'MY_EVENT is enabled'); + expect(MY_EVENT.uses).to.eq(1, 'MY_EVENT uses has been increased by 1'); + expect(eventCallCount).to.eq(1, 'eventCallCount has been increased by 1'); + expect(JSON.stringify(currentEventPayload)).to.eq(JSON.stringify({title: 'test', message: 'messageTest'}), 'currentEventPayload has correct value'); + + // Trigger Event + MY_EVENT.trigger({title: 'test2', message: 'messageTest2'}); + + expect(MY_EVENT.enabled).to.eq(true, 'MY_EVENT is enabled'); + expect(MY_EVENT.uses).to.eq(2, 'MY_EVENT uses has been increased by 1'); + expect(eventCallCount).to.eq(2, 'eventCallCount has been increased by 1'); + expect(JSON.stringify(currentEventPayload)).to.eq(JSON.stringify({title: 'test2', message: 'messageTest2'}), 'currentEventPayload has correct value'); + + // Trigger Event + MY_EVENT.trigger({title: 'test3', message: 'messageTest3'}); + + expect(MY_EVENT.enabled).to.eq(false, 'MY_EVENT got disabled'); + expect(MY_EVENT.uses).to.eq(3, 'MY_EVENT uses has been increased by 1'); + expect(eventCallCount).to.eq(3, 'eventCallCount has been increased by 1'); + expect(JSON.stringify(currentEventPayload)).to.eq(JSON.stringify({title: 'test3', message: 'messageTest3'}), 'currentEventPayload has correct value'); + + // Trigger Event + MY_EVENT.trigger({title: 'test4', message: 'messageTest4'}); + + expect(MY_EVENT.enabled).to.eq(false, 'MY_EVENT is disabled'); + expect(MY_EVENT.uses).to.eq(3, 'MY_EVENT uses stayed the same'); + expect(eventCallCount).to.eq(3, 'eventCallCount stayed the same'); + expect(JSON.stringify(currentEventPayload)).to.eq(JSON.stringify({title: 'test3', message: 'messageTest3'}), 'currentEventPayload stayed the same'); }); }); }); From b33e1236113c0a0c6ddfd1a41e034cb853768850 Mon Sep 17 00:00:00 2001 From: Benno Kohrs Date: Sat, 12 Sep 2020 20:50:35 +0200 Subject: [PATCH 17/25] Created trigger function tests --- test/event/functions/trigger.function.spec.ts | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 test/event/functions/trigger.function.spec.ts diff --git a/test/event/functions/trigger.function.spec.ts b/test/event/functions/trigger.function.spec.ts new file mode 100644 index 00000000..0e77bb8b --- /dev/null +++ b/test/event/functions/trigger.function.spec.ts @@ -0,0 +1,66 @@ +import 'mocha'; +import {expect} from 'chai'; +import Agile from "../../../src"; +import {useEvent} from "../../../src/integrations/test"; + +describe('Trigger Function Tests', () => { + // Define Agile + const App = new Agile(); + + interface EventPayload { + title: string + message: string + } + + describe('Event', () => { + let eventCallCount = 0; + let currentEventPayload; + + // Create Event + const MY_EVENT = App.Event(); + + MY_EVENT.on((payload) => { + eventCallCount++; + currentEventPayload = payload; + }); + + // @ts-ignore + useEvent(MY_EVENT, (payload => { + eventCallCount++; + currentEventPayload = payload; + })); + + it('Has correct initial value', () => { + expect(MY_EVENT.uses).to.eq(0, 'MY_EVENT uses has correct initial value'); + expect(JSON.stringify(MY_EVENT.config)).to.eq(JSON.stringify({enabled: true}), 'MY_EVENT has correct initial config'); + expect(MY_EVENT.callbacks.size).to.eq(2, 'MY_EVENT has correct callbacks size'); + expect(MY_EVENT.enabled).to.eq(true, 'MY_EVENT is enabled'); + + expect(eventCallCount).to.eq(0, 'eventCallCount has correct initial size'); + expect(currentEventPayload).to.eq(undefined, 'currentEventPayload has correct initial value'); + }); + + it('Can trigger enabled Event', async () => { + // Trigger Event + MY_EVENT.trigger({title: "Hello", message: "There"}); + + expect(MY_EVENT.uses).to.eq(1, 'MY_EVENT uses has been increased by 1'); + + expect(eventCallCount).to.eq(2, 'eventCallCount has been increased by 2'); + expect(JSON.stringify(currentEventPayload)).to.eq(JSON.stringify({title: "Hello", message: "There"}), 'currentEventPayload has correct value'); + }); + + it('Can\'t trigger disabled Event', async () => { + // Disable Event + MY_EVENT.disable(); + + // Trigger Event + MY_EVENT.trigger({title: "Hello", message: "There"}); + + expect(MY_EVENT.uses).to.eq(1, 'MY_EVENT uses stayed the same'); + + expect(eventCallCount).to.eq(2, 'eventCallCount stayed the same'); + expect(JSON.stringify(currentEventPayload)).to.eq(JSON.stringify({title: "Hello", message: "There"}), 'currentEventPayload has correct value'); + }); + }); +}); From 71b7e63d96693533a94b04bb9965b3d8ac6ee68c Mon Sep 17 00:00:00 2001 From: Benno Kohrs Date: Sat, 12 Sep 2020 20:52:17 +0200 Subject: [PATCH 18/25] Added event to example --- examples/react-typescript/src/App.tsx | 24 +++++++++++++++------ examples/react-typescript/src/core/index.ts | 2 ++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/examples/react-typescript/src/App.tsx b/examples/react-typescript/src/App.tsx index 6e87f8d5..5d2fa97b 100644 --- a/examples/react-typescript/src/App.tsx +++ b/examples/react-typescript/src/App.tsx @@ -1,21 +1,24 @@ import React from 'react'; -import logo from './logo.svg'; import './App.css'; -import {useAgile} from 'agile-framework'; -import {MY_COLLECTION, MY_COMPUTED, MY_STATE, MY_STATE_2} from "./core"; +import {useAgile, useEvent} from 'agile-framework'; +import {MY_COLLECTION, MY_COMPUTED, MY_EVENT, MY_STATE, MY_STATE_2} from "./core"; const App = (props: any) => { const [myComputed] = useAgile([MY_COMPUTED]); const [myState, myState2] = useAgile([MY_STATE, MY_STATE_2]); const [myCollection] = useAgile([MY_COLLECTION.getGroup('myGroup')]); - const [mySelector] = useAgile([MY_COLLECTION.getSelector('mySelector')]); + const mySelector = useAgile(MY_COLLECTION.getSelector('mySelector')); + useEvent(MY_EVENT, () => { + console.log("Triggered Event"); + }); console.log("myComputed", MY_COMPUTED); console.log("myState", MY_STATE); console.log("myState2", MY_STATE_2); console.log("myCollection", MY_COLLECTION); + console.log("myEvent", MY_EVENT); return ( @@ -47,6 +50,15 @@ const App = (props: any) => {

+
+

My Event

+ +
+

My Collection

@@ -72,11 +84,11 @@ const App = (props: any) => {
-

MySelector: {mySelector.name}

+

MySelector: {mySelector?.name}

diff --git a/examples/react-typescript/src/core/index.ts b/examples/react-typescript/src/core/index.ts index 6c2fe600..07954424 100644 --- a/examples/react-typescript/src/core/index.ts +++ b/examples/react-typescript/src/core/index.ts @@ -35,3 +35,5 @@ export const MY_COLLECTION = App.Collection(collection MY_COLLECTION.collect({id: 'id1', name: 'test'}); MY_COLLECTION.collect({id: 'id2', name: 'test2'}, 'myGroup'); console.log("Initial: myCollection ", MY_COLLECTION); + +export const MY_EVENT = App.Event<{name: string}>(); From b75ef998edd3572886d6581d7178041338ef55f7 Mon Sep 17 00:00:00 2001 From: Benno Kohrs Date: Sun, 13 Sep 2020 09:22:34 +0200 Subject: [PATCH 19/25] created on function tests on optimized trigger function tests --- test/event/functions/on.function.spec.ts | 47 +++++++++++ test/event/functions/trigger.function.spec.ts | 82 ++++++++++--------- 2 files changed, 90 insertions(+), 39 deletions(-) create mode 100644 test/event/functions/on.function.spec.ts diff --git a/test/event/functions/on.function.spec.ts b/test/event/functions/on.function.spec.ts new file mode 100644 index 00000000..6047b2b3 --- /dev/null +++ b/test/event/functions/on.function.spec.ts @@ -0,0 +1,47 @@ +import 'mocha'; +import {expect} from 'chai'; +import Agile from "../../../src"; + +describe('On Function Tests', () => { + let eventCallCount = 0; + let currentEventPayload; + + // Define Agile + const App = new Agile(); + + interface EventPayload { + title: string + message: string + } + + // Create Event + const MY_EVENT = App.Event(); + + MY_EVENT.on((payload) => { + eventCallCount++; + currentEventPayload = payload; + }); + + it('Has correct initial value', () => { + expect(MY_EVENT.uses).to.eq(0, 'MY_EVENT uses has correct initial value'); + expect(JSON.stringify(MY_EVENT.config)).to.eq(JSON.stringify({enabled: true}), 'MY_EVENT has correct initial config'); + expect(MY_EVENT.callbacks.size).to.eq(1, 'MY_EVENT has correct callbacks size'); + expect(MY_EVENT.enabled).to.eq(true, 'MY_EVENT is enabled'); + + expect(eventCallCount).to.eq(0, 'eventCallCount has correct initial size'); + expect(currentEventPayload).to.eq(undefined, 'currentEventPayload has correct initial value'); + }); + + it('Does call on callback by triggering Event', async () => { + // Trigger Event + MY_EVENT.trigger({title: "Hello", message: "There"}); + + expect(MY_EVENT.uses).to.eq(1, 'MY_EVENT uses has been increased by 1'); + + expect(eventCallCount).to.eq(1, 'eventCallCount has been increased by 2'); + expect(JSON.stringify(currentEventPayload)).to.eq(JSON.stringify({ + title: "Hello", + message: "There" + }), 'currentEventPayload has correct value'); + }); +}); diff --git a/test/event/functions/trigger.function.spec.ts b/test/event/functions/trigger.function.spec.ts index 0e77bb8b..78cc23e3 100644 --- a/test/event/functions/trigger.function.spec.ts +++ b/test/event/functions/trigger.function.spec.ts @@ -4,6 +4,9 @@ import Agile from "../../../src"; import {useEvent} from "../../../src/integrations/test"; describe('Trigger Function Tests', () => { + let eventCallCount = 0; + let currentEventPayload; + // Define Agile const App = new Agile(); @@ -12,55 +15,56 @@ describe('Trigger Function Tests', () => { message: string } - describe('Event', () => { - let eventCallCount = 0; - let currentEventPayload; - - // Create Event - const MY_EVENT = App.Event(); + // Create Event + const MY_EVENT = App.Event(); - MY_EVENT.on((payload) => { - eventCallCount++; - currentEventPayload = payload; - }); + MY_EVENT.on((payload) => { + eventCallCount++; + currentEventPayload = payload; + }); - // @ts-ignore - useEvent(MY_EVENT, (payload => { - eventCallCount++; - currentEventPayload = payload; - })); + // @ts-ignore + useEvent(MY_EVENT, (payload => { + eventCallCount++; + currentEventPayload = payload; + })); - it('Has correct initial value', () => { - expect(MY_EVENT.uses).to.eq(0, 'MY_EVENT uses has correct initial value'); - expect(JSON.stringify(MY_EVENT.config)).to.eq(JSON.stringify({enabled: true}), 'MY_EVENT has correct initial config'); - expect(MY_EVENT.callbacks.size).to.eq(2, 'MY_EVENT has correct callbacks size'); - expect(MY_EVENT.enabled).to.eq(true, 'MY_EVENT is enabled'); + it('Has correct initial value', () => { + expect(MY_EVENT.uses).to.eq(0, 'MY_EVENT uses has correct initial value'); + expect(JSON.stringify(MY_EVENT.config)).to.eq(JSON.stringify({enabled: true}), 'MY_EVENT has correct initial config'); + expect(MY_EVENT.callbacks.size).to.eq(2, 'MY_EVENT has correct callbacks size'); + expect(MY_EVENT.enabled).to.eq(true, 'MY_EVENT is enabled'); - expect(eventCallCount).to.eq(0, 'eventCallCount has correct initial size'); - expect(currentEventPayload).to.eq(undefined, 'currentEventPayload has correct initial value'); - }); + expect(eventCallCount).to.eq(0, 'eventCallCount has correct initial size'); + expect(currentEventPayload).to.eq(undefined, 'currentEventPayload has correct initial value'); + }); - it('Can trigger enabled Event', async () => { - // Trigger Event - MY_EVENT.trigger({title: "Hello", message: "There"}); + it('Can trigger enabled Event', async () => { + // Trigger Event + MY_EVENT.trigger({title: "Hello", message: "There"}); - expect(MY_EVENT.uses).to.eq(1, 'MY_EVENT uses has been increased by 1'); + expect(MY_EVENT.uses).to.eq(1, 'MY_EVENT uses has been increased by 1'); - expect(eventCallCount).to.eq(2, 'eventCallCount has been increased by 2'); - expect(JSON.stringify(currentEventPayload)).to.eq(JSON.stringify({title: "Hello", message: "There"}), 'currentEventPayload has correct value'); - }); + expect(eventCallCount).to.eq(2, 'eventCallCount has been increased by 2'); + expect(JSON.stringify(currentEventPayload)).to.eq(JSON.stringify({ + title: "Hello", + message: "There" + }), 'currentEventPayload has correct value'); + }); - it('Can\'t trigger disabled Event', async () => { - // Disable Event - MY_EVENT.disable(); + it('Can\'t trigger disabled Event', async () => { + // Disable Event + MY_EVENT.enabled = false; - // Trigger Event - MY_EVENT.trigger({title: "Hello", message: "There"}); + // Trigger Event + MY_EVENT.trigger({title: "Hello", message: "There"}); - expect(MY_EVENT.uses).to.eq(1, 'MY_EVENT uses stayed the same'); + expect(MY_EVENT.uses).to.eq(1, 'MY_EVENT uses stayed the same'); - expect(eventCallCount).to.eq(2, 'eventCallCount stayed the same'); - expect(JSON.stringify(currentEventPayload)).to.eq(JSON.stringify({title: "Hello", message: "There"}), 'currentEventPayload has correct value'); - }); + expect(eventCallCount).to.eq(2, 'eventCallCount stayed the same'); + expect(JSON.stringify(currentEventPayload)).to.eq(JSON.stringify({ + title: "Hello", + message: "There" + }), 'currentEventPayload has correct value'); }); }); From a5738ef3022cdb7bdf9c134ffd68391c6bb35add Mon Sep 17 00:00:00 2001 From: Benno Kohrs Date: Sun, 13 Sep 2020 09:33:06 +0200 Subject: [PATCH 20/25] Created disable function tests --- test/event/functions/disable.function.spec.ts | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 test/event/functions/disable.function.spec.ts diff --git a/test/event/functions/disable.function.spec.ts b/test/event/functions/disable.function.spec.ts new file mode 100644 index 00000000..96f402d9 --- /dev/null +++ b/test/event/functions/disable.function.spec.ts @@ -0,0 +1,31 @@ +import 'mocha'; +import {expect} from 'chai'; +import Agile from "../../../src"; + +describe('Disable Function Tests', () => { + // Define Agile + const App = new Agile(); + + interface EventPayload { + title: string + message: string + } + + // Create Event + const MY_EVENT = App.Event(); + + it('Has correct initial value', () => { + expect(MY_EVENT.uses).to.eq(0, 'MY_EVENT uses has correct initial value'); + expect(JSON.stringify(MY_EVENT.config)).to.eq(JSON.stringify({enabled: true}), 'MY_EVENT has correct initial config'); + expect(MY_EVENT.enabled).to.eq(true, 'MY_EVENT is enabled'); + }); + + it('Can disable Event', () => { + // Disable Event + MY_EVENT.disable(); + + expect(MY_EVENT.uses).to.eq(0, 'MY_EVENT uses stayed the same'); + expect(JSON.stringify(MY_EVENT.config)).to.eq(JSON.stringify({enabled: true}), 'MY_EVENT has correct config'); + expect(MY_EVENT.enabled).to.eq(false, 'MY_EVENT is disabled'); + }); +}); From 348e9db4b102043c8b067086d8a4a388d371a571 Mon Sep 17 00:00:00 2001 From: Benno Kohrs Date: Sun, 13 Sep 2020 09:34:37 +0200 Subject: [PATCH 21/25] Created enable function tests --- test/event/functions/enable.function.spec.ts | 31 ++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 test/event/functions/enable.function.spec.ts diff --git a/test/event/functions/enable.function.spec.ts b/test/event/functions/enable.function.spec.ts new file mode 100644 index 00000000..86a37901 --- /dev/null +++ b/test/event/functions/enable.function.spec.ts @@ -0,0 +1,31 @@ +import 'mocha'; +import {expect} from 'chai'; +import Agile from "../../../src"; + +describe('Enable Function Tests', () => { + // Define Agile + const App = new Agile(); + + interface EventPayload { + title: string + message: string + } + + // Create Event + const MY_EVENT = App.Event({enabled: false}); + + it('Has correct initial value', () => { + expect(MY_EVENT.uses).to.eq(0, 'MY_EVENT uses has correct initial value'); + expect(JSON.stringify(MY_EVENT.config)).to.eq(JSON.stringify({enabled: false}), 'MY_EVENT has correct initial config'); + expect(MY_EVENT.enabled).to.eq(false, 'MY_EVENT is disabled'); + }); + + it('Can enable Event', () => { + // Disable Event + MY_EVENT.enable(); + + expect(MY_EVENT.uses).to.eq(0, 'MY_EVENT uses stayed the same'); + expect(JSON.stringify(MY_EVENT.config)).to.eq(JSON.stringify({enabled: false}), 'MY_EVENT has correct config'); + expect(MY_EVENT.enabled).to.eq(true, 'MY_EVENT is enabled'); + }); +}); From b3626fc4b5d764c4bcf2fbc85e4fc475a301c079 Mon Sep 17 00:00:00 2001 From: Benno Kohrs Date: Sun, 13 Sep 2020 09:42:22 +0200 Subject: [PATCH 22/25] Created reset function tests and fixed small typo --- test/event/functions/enable.function.spec.ts | 2 +- test/event/functions/reset.function.spec.ts | 36 ++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 test/event/functions/reset.function.spec.ts diff --git a/test/event/functions/enable.function.spec.ts b/test/event/functions/enable.function.spec.ts index 86a37901..75f68673 100644 --- a/test/event/functions/enable.function.spec.ts +++ b/test/event/functions/enable.function.spec.ts @@ -21,7 +21,7 @@ describe('Enable Function Tests', () => { }); it('Can enable Event', () => { - // Disable Event + // Enable Event MY_EVENT.enable(); expect(MY_EVENT.uses).to.eq(0, 'MY_EVENT uses stayed the same'); diff --git a/test/event/functions/reset.function.spec.ts b/test/event/functions/reset.function.spec.ts new file mode 100644 index 00000000..18dead87 --- /dev/null +++ b/test/event/functions/reset.function.spec.ts @@ -0,0 +1,36 @@ +import 'mocha'; +import {expect} from 'chai'; +import Agile from "../../../src"; + +describe('Reset Function Tests', () => { + // Define Agile + const App = new Agile(); + + interface EventPayload { + title: string + message: string + } + + // Create Event + const MY_EVENT = App.Event(); + + // Trigger and disable Event + MY_EVENT.trigger(); + MY_EVENT.trigger(); + MY_EVENT.disable(); + + it('Has correct initial value', () => { + expect(MY_EVENT.uses).to.eq(2, 'MY_EVENT uses has correct initial value'); + expect(JSON.stringify(MY_EVENT.config)).to.eq(JSON.stringify({enabled: true}), 'MY_EVENT has correct initial config'); + expect(MY_EVENT.enabled).to.eq(false, 'MY_EVENT is disabled'); + }); + + it('Can reset Event', () => { + // Reset Event + MY_EVENT.reset(); + + expect(MY_EVENT.uses).to.eq(0, 'MY_EVENT uses has been reset'); + expect(JSON.stringify(MY_EVENT.config)).to.eq(JSON.stringify({enabled: true}), 'MY_EVENT has correct config'); + expect(MY_EVENT.enabled).to.eq(true, 'MY_EVENT is enabled'); + }); +}); From 59a326e733241e1d7f6570ddbc17c0724298f282 Mon Sep 17 00:00:00 2001 From: Benno Kohrs Date: Sun, 13 Sep 2020 16:42:28 +0200 Subject: [PATCH 23/25] Setup package --- .npmignore | 3 +-- package.json | 7 ++++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.npmignore b/.npmignore index f30eb650..b958d4ac 100644 --- a/.npmignore +++ b/.npmignore @@ -1,2 +1 @@ -examples -test +"files": ["dist/**/*"] diff --git a/package.json b/package.json index 1a6bbdb8..c5ebc49e 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,12 @@ "scripts": { "build": "tsc", "dev": "tsc-watch", - "test": "mocha -r ts-node/register --exit test/**/*.spec.ts" + "test": "mocha -r ts-node/register --exit test/**/*.spec.ts", + + "prepare" : "npm run build", + "prepublishOnly" : "npm test", + "version" : "npm run format && git add -A src", + "postversion" : "git push && git push --tags" }, "types": "./dist/index.d.ts", "author": "BennoDev", From d4da3e4974059b1ce74167620f2dc746394c9d74 Mon Sep 17 00:00:00 2001 From: Benno Kohrs Date: Sun, 13 Sep 2020 17:12:25 +0200 Subject: [PATCH 24/25] Made package smaller --- .npmignore | 1 - ReadMe.md | 2 +- package.json | 28 +++++++++++++++++++--------- 3 files changed, 20 insertions(+), 11 deletions(-) delete mode 100644 .npmignore diff --git a/.npmignore b/.npmignore deleted file mode 100644 index b958d4ac..00000000 --- a/.npmignore +++ /dev/null @@ -1 +0,0 @@ -"files": ["dist/**/*"] diff --git a/ReadMe.md b/ReadMe.md index 6cb11c28..c59d282b 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -1,4 +1,4 @@ -# Agile Framework `1.1` +# Agile Framework `1.0.2` _Agile is a global state and logic framework for reactive Typescript & Javascript applications. Supporting frameworks like React and React Native._ diff --git a/package.json b/package.json index c5ebc49e..b16bde15 100644 --- a/package.json +++ b/package.json @@ -1,20 +1,27 @@ { - "name": "agile-framework", - "version": "1.0.0", + "name": "agile-architecture", + "version": "1.0.2", "description": "Global state and logic framework for reactive React applications.", "main": "dist/index.js", "module": "dist/index.js", + "types": "./dist/index.d.ts", "scripts": { "build": "tsc", "dev": "tsc-watch", "test": "mocha -r ts-node/register --exit test/**/*.spec.ts", - - "prepare" : "npm run build", - "prepublishOnly" : "npm test", - "version" : "npm run format && git add -A src", - "postversion" : "git push && git push --tags" + "prepare": "npm run build", + "prepublishOnly": "npm test", + "version": "npm run format && git add -A src", + "postversion": "git push && git push --tags" }, - "types": "./dist/index.d.ts", + "repository": { + "type": "git", + "url": "git+https://github.com/agile-architecture/agile.git" + }, + "keywords": [ + "React", + "State-Management" + ], "author": "BennoDev", "license": "ISC", "dependencies": { @@ -29,5 +36,8 @@ "tsc-watch": "^4.1.0", "tslib": "^2.0.0", "typescript": "^3.9.7" - } + }, + "files": [ + "dist/**/*" + ] } From 8a175f8d8b51e98c58d47805f45c84d09148e006 Mon Sep 17 00:00:00 2001 From: Benno Kohrs Date: Mon, 28 Sep 2020 09:27:18 +0200 Subject: [PATCH 25/25] Updated Name --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index c5c85fd6..2ebbfae5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { - "name": "agile-framework", - "version": "1.0.0", + "name": "agile", + "version": "1.0.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index b16bde15..3203580b 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "agile-architecture", + "name": "agile", "version": "1.0.2", "description": "Global state and logic framework for reactive React applications.", "main": "dist/index.js",