From cb7bbf1ede054e5c249e5a168c9d612ffa9b3563 Mon Sep 17 00:00:00 2001 From: REllEK-IO Date: Thu, 16 May 2024 16:17:20 -0700 Subject: [PATCH] Removed Buffer v0.1.71 --- ActionStrategy.md | 11 -- README.md | 7 +- package.json | 2 +- src/index.ts | 6 - src/model/method.ts | 143 -------------- src/test/bufferMethods/bufferMethods.test.ts | 186 ------------------ ...ltiplyByCountFromConceptsAction.quality.ts | 33 ---- ...ltiplyByCountFromConceptsAction.quality.ts | 31 --- .../qualities/bufferSomeAction.quality.ts | 32 --- 9 files changed, 4 insertions(+), 447 deletions(-) delete mode 100644 src/test/bufferMethods/bufferMethods.test.ts delete mode 100644 src/test/bufferMethods/qualities/asyncBufferMultiplyByCountFromConceptsAction.quality.ts delete mode 100644 src/test/bufferMethods/qualities/bufferMultiplyByCountFromConceptsAction.quality.ts delete mode 100644 src/test/bufferMethods/qualities/bufferSomeAction.quality.ts diff --git a/ActionStrategy.md b/ActionStrategy.md index b9d489a..f0a875b 100644 --- a/ActionStrategy.md +++ b/ActionStrategy.md @@ -182,16 +182,6 @@ export const createAsyncMethodThrottle = export const createAsyncMethodThrottleWithState = (asyncMethodWithState: (controller: ActionController, action: Action, concepts: Concepts) => void, concepts$: UnifiedSubject, semaphore: number, duration: number): [Method, Subject] => {} -export const createMethodBuffer = - (method: (action: Action) => Action, duration: number): [Method, Subject] => {} -export const createMethodBufferWithState = - (methodWithState: (action: Action, concepts: Concepts) => Action, concepts$: UnifiedSubject, semaphore: number, duration: number) - : [Method, Subject] => {} -export const createAsyncMethodBuffer = - (asyncMethod: (controller: ActionController, action: Action) => void, duration: number): [Method, Subject] => {} -export const createAsyncMethodBufferWithState = - (asyncMethodWithState: (controller: ActionController, action: Action, concepts: Concepts) => - void, concepts$: UnifiedSubject, semaphore: number, duration: number): [Method, Subject] => {} ``` * createMethod - Your standard method, be sure to handle the action.strategy via one of the strategy decision functions, in addition to passing the action if there is no attached strategy. * createMethodWithState - This will allow your method to have the most recent state to be accessed via the asyncMethod function. @@ -207,7 +197,6 @@ export const createAsyncMethodBufferWithState = * createMethodThrottleWithState- Fires the first action, alongside the most recent state, then filters rest as conclude. * createAsyncMethodThrottle - Asynchronously fires the first action, will filtering the rest for the set duration as conclude. * createAsyncMethodThrottleWithState - Fires the first action asynchronously with the most recent state, and filters action during the duration as conclude to remove stale tickers from ownership if loaded. -* **Buffer Series** similar to debounce method series, but will issue each possible action that encounters the quality for a length of time. Note these will fail ActionStrategies whose time has expired. ## "Creator Functions" Note here this is merely a guideline to inform the creation of your strategies. diff --git a/README.md b/README.md index 475489b..7e48598 100644 --- a/README.md +++ b/README.md @@ -49,10 +49,9 @@ When in doubt simplify. * [Unified Turing Machine](https://github.com/Phuire-Research/Stratimux/blob/main/The-Unified-Turing-Machine.md) - The governing concept for this entire framework. ## Change Log ![Tests](https://github.com/Phuire-Research/Stratimux/actions/workflows/node.js.yml/badge.svg) -### Consistency Update v0.1.70 5/16/2024 -* Added new buffer method series that will delay the dispatch of some possible set of actions for a period of time. - * **NOTE CURRENTLY INVESTIGATING WHY BUFFER WORKS IN ISOLATION, BUT NOT IN A COMPLEX SET UP** -* Finally removed the need to add "as Subject | UnifiedSubject" when creating methods that access state or concepts. +### Consistency Update v0.1.71 5/16/2024 +* Finally removed the need to add "as Subject | UnifiedSubject" when creating methods that access state or concepts. +* Added then **removed** a new Buffer Method Creator Series. See branch Stash-Buffer for details. ### v0.1.69 5/15/2024 * Added priority to axium strategies. * Improved consistency of logic due the above change. diff --git a/package.json b/package.json index f7c3afd..7ab36a8 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "stratimux", "license": "GPL-3.0", - "version": "0.1.70", + "version": "0.1.71", "description": "Unified Turing Machine", "main": "dist/index.js", "module": "dist/index.mjs", diff --git a/src/index.ts b/src/index.ts index 9903df1..e9d56db 100644 --- a/src/index.ts +++ b/src/index.ts @@ -55,12 +55,6 @@ export { createMethodDebounceWithConcepts, createAsyncMethodThrottleWithConcepts, createAsyncMethodDebounceWithConcepts, - createMethodBuffer, - createMethodBufferWithState, - createMethodBufferWithConcepts, - createAsyncMethodBuffer, - createAsyncMethodBufferWithConcepts, - createAsyncMethodBufferWithState, method } from './model/method'; export { diff --git a/src/model/method.ts b/src/model/method.ts index 6841099..8b4170e 100644 --- a/src/model/method.ts +++ b/src/model/method.ts @@ -98,143 +98,6 @@ export const createAsyncMethodWithState = defaultMethod.toString = () => ('Async Method with State'); return [defaultMethod, defaultSubject]; }; -export const createMethodBuffer = - (method: (action: Action) => Action, duration: number): [Method, Subject] => { - const defaultSubject = new Subject(); - const defaultMethod: Method = defaultSubject.pipe( - bufferTime(duration), - filter(actions => actions.length > 0), - switchMap(actions => createActionControllerForEach$(actions)), - map((action: Action) => { - // Logically Determined axiumConclude - if (action.semaphore[3] !== 3) { - const methodAction = method(action); - if (methodAction.strategy) { - return [methodAction, true]; - } - const conclude = axiumConclude(); - return [{ - ...action, - ...conclude, - }, false]; - } else { - return [action, true]; - } - }), - ); - defaultMethod.toString = () => ('Debounce Method'); - return [defaultMethod, defaultSubject]; - }; -export const createMethodBufferWithState = - (methodWithState: - (action: Action, state: T) => Action, concepts$: Subject, semaphore: number, duration: number): [Method, Subject] => { - const defaultSubject = new Subject(); - const defaultMethod: Method = defaultSubject.pipe( - bufferTime(duration), - switchMap(actions => createActionControllerForEach$(actions)), - withLatestFrom(concepts$), - map(([act, concepts] : [Action, Concepts]): [Action, T] => ([act, selectUnifiedState(concepts, semaphore) as T])), - map(([act, state] : [Action, T]) => { - // Logically Determined axiumConclude - if (act.semaphore[3] !== 3) { - const methodAction = methodWithState(act, state); - if (methodAction.strategy) { - return [methodAction, true]; - } - const conclude = axiumConclude(); - return [{ - ...act, - ...conclude, - }, true]; - } else { - return [act, true]; - } - }), - ); - defaultMethod.toString = () => ('Buffer Method with State'); - return [defaultMethod, defaultSubject]; - }; -export const createMethodBufferWithConcepts = - ( - methodWithConcepts: (action: Action, concepts: Concepts, semaphore: number) => Action, concepts$: Subject, - semaphore: number, - duration: number - ) : [Method, Subject] => { - const defaultSubject = new Subject(); - const defaultMethod: Method = defaultSubject.pipe( - bufferTime(duration), - switchMap(actions => createActionControllerForEach$(actions)), - withLatestFrom(concepts$), - map(([act, concepts] : [Action, Concepts]) => { - // Logically Determined axiumConclude - if (act.semaphore[3] !== 3) { - const methodAction = methodWithConcepts(act, concepts, semaphore); - if (methodAction.strategy) { - return [methodAction, true]; - } - const conclude = axiumConclude(); - return [{ - ...act, - ...conclude, - }, false]; - } else { - return [act, true]; - } - }), - ); - defaultMethod.toString = () => ('Buffer Method with Concepts'); - return [defaultMethod, defaultSubject]; - }; -export const createAsyncMethodBuffer = - (asyncMethod: (controller: ActionController, action: Action) => void, duration: number): [Method, Subject] => { - const defaultSubject = new Subject(); - const defaultMethod: Method = defaultSubject.pipe( - bufferTime(duration), - switchMap(actions => createActionControllerForEach$(actions)), - mergeMap((act) => { - return createActionController$(act, (controller: ActionController, action: Action) => { - asyncMethod(controller, action); - }); - }), - ); - defaultMethod.toString = () => ('Async Buffer Method'); - return [defaultMethod, defaultSubject]; - }; -export const createAsyncMethodBufferWithState = - (asyncMethodWithState: (controller: ActionController, action: Action, state: T) => - void, concepts$: Subject, semaphore: number, duration: number, ): [Method, Subject] => { - const defaultSubject = new Subject(); - const defaultMethod: Method = defaultSubject.pipe( - bufferTime(duration), - switchMap(actions => createActionControllerForEach$(actions)), - withLatestFrom(concepts$), - map(([act, concepts] : [Action, Concepts]): [Action, T] => ([act, selectUnifiedState(concepts, semaphore) as T])), - mergeMap(([act, state] : [Action, T]) => { - return createActionController$(act, (controller: ActionController, action: Action) => { - asyncMethodWithState(controller, action, state); - }); - }) - ); - defaultMethod.toString = () => ('Async Buffer Method with State'); - return [defaultMethod, defaultSubject]; - }; -export const createAsyncMethodBufferWithConcepts = - (asyncMethodWithConcepts: (controller: ActionController, action: Action, concepts: Concepts, semaphore: number) => - void, concepts$: Subject, semaphore: number, duration: number, ): [Method, Subject] => { - const defaultSubject = new Subject(); - const defaultMethod: Method = defaultSubject.pipe( - bufferTime(duration), - switchMap(actions => createActionControllerForEach$(actions)), - withLatestFrom(concepts$), - mergeMap(([act, concepts] : [Action, Concepts]) => { - return createActionController$(act, (controller: ActionController, action: Action) => { - asyncMethodWithConcepts(controller, action, concepts, semaphore); - }); - }), - ); - defaultMethod.toString = () => ('Async Buffer Method with Concepts'); - return [defaultMethod, defaultSubject]; - }; export const createMethodDebounce = (method: (action: Action) => Action, duration: number): [Method, Subject] => { const defaultSubject = new Subject(); @@ -555,11 +418,5 @@ export const method = ({ createAsyncThrottle: createAsyncMethodThrottle, createAsyncThrottleWithState: createAsyncMethodThrottleWithState, createAsyncThrottleWithConcepts: createAsyncMethodThrottleWithConcepts, - createBuffer: createMethodBuffer, - createBufferWithState: createMethodBufferWithState, - createMethodBufferWithConcepts: createMethodBufferWithConcepts, - createAsyncBuffer: createAsyncMethodBuffer, - createAsyncBufferWithState: createAsyncMethodBufferWithState, - createAsyncBufferWithConcepts: createAsyncMethodBufferWithConcepts }); /*#>*/ \ No newline at end of file diff --git a/src/test/bufferMethods/bufferMethods.test.ts b/src/test/bufferMethods/bufferMethods.test.ts deleted file mode 100644 index 8c60c64..0000000 --- a/src/test/bufferMethods/bufferMethods.test.ts +++ /dev/null @@ -1,186 +0,0 @@ -/*<$ -For the asynchronous graph programming framework Stratimux, generate a tests and demonstrates how buffer methods perform their functionality. -$>*/ -/*<#*/ -import { axiumKick } from '../../concepts/axium/qualities/kick.quality'; -import { CounterState, counterName, createCounterConcept } from '../../concepts/counter/counter.concept'; -import { counterSelectCount } from '../../concepts/counter/counter.selector'; -import { counterAdd } from '../../concepts/counter/qualities/add.quality'; -import { counterSetCount } from '../../concepts/counter/qualities/setCount.quality'; -import { createExperimentConcept, createExperimentState } from '../../concepts/experiment/experiment.concept'; -import { createAxium } from '../../model/axium'; -import { selectState } from '../../model/selector'; -import { createStage, stageWaitForOpenThenIterate } from '../../model/stagePlanner'; -import { - experimentAsyncBufferMultiplyByCountFromConcepts, - experimentAsyncBufferMultiplyByCountFromConceptsQuality -} from './qualities/asyncBufferMultiplyByCountFromConceptsAction.quality'; -import { - experimentBufferMultiplyByCountFromConcepts, - experimentBufferMultiplyByCountFromConceptsQuality -} from './qualities/bufferMultiplyByCountFromConceptsAction.quality'; -import { experimentBufferNextAction, experimentBufferNextActionQuality } from './qualities/bufferSomeAction.quality'; - -test('Buffer method periodic count', (done) => { - const experiment = createExperimentConcept(createExperimentState(), [experimentBufferNextActionQuality]); - const axium = createAxium('Experiment method buffer defer actions', [createCounterConcept(), experiment]); - const plan = axium.plan('Experiment buffer add 4 after 10ms', [ - stageWaitForOpenThenIterate(() => axiumKick()), - createStage((_, dispatch) => { - dispatch(experimentBufferNextAction({ - action: counterAdd() - }), { - iterateStage: true, - }); - }), - createStage((concepts, dispatch) => { - const counterState = selectState(concepts, counterName); - expect(counterState?.count).toBe(0); - dispatch(experimentBufferNextAction({ - action: counterAdd() - }), { - iterateStage: true, - }); - }), - createStage((concepts, dispatch) => { - const counterState = selectState(concepts, counterName); - expect(counterState?.count).toBe(0); - dispatch(experimentBufferNextAction({ - action: counterAdd() - }), { - iterateStage: true, - }); - }), - createStage((concepts, dispatch) => { - const counterState = selectState(concepts, counterName); - expect(counterState?.count).toBe(0); - dispatch(experimentBufferNextAction({ - action: counterAdd() - }), { - iterateStage: true, - }); - }), - createStage((concepts, _dispatch, changes) => { - const counterState = selectState(concepts, counterName); - if (changes.length > 0) { - expect(counterState?.count).toBe(4); - setTimeout(() => { - plan.conclude(); - axium.close(); - done(); - }, 10); - } - }, {selectors: [counterSelectCount], beat: 200}), - createStage(() => { - plan.conclude(); - }) - ]); -}); - -test('Buffer method with concept towards final multiply of count', (done) => { - const experiment = createExperimentConcept(createExperimentState(), [experimentBufferMultiplyByCountFromConceptsQuality]); - const axium = createAxium('Experiment method buffer defer multiply', [createCounterConcept(), experiment]); - const plan = axium.plan('Experiment buffer multiply by 2 from concept state after 10ms', [ - stageWaitForOpenThenIterate(() => axiumKick()), - createStage((_, dispatch) => { - dispatch(counterSetCount({ - newCount: 2 - }), { - iterateStage: true, - }); - }), - createStage((concepts, dispatch) => { - const counterState = selectState(concepts, counterName); - expect(counterState?.count).toBe(2); - dispatch(experimentBufferMultiplyByCountFromConcepts(), { - iterateStage: true, - }); - }), - createStage((concepts, dispatch) => { - const counterState = selectState(concepts, counterName); - expect(counterState?.count).toBe(2); - dispatch(experimentBufferMultiplyByCountFromConcepts(), { - iterateStage: true, - }); - }), - createStage((concepts, dispatch) => { - const counterState = selectState(concepts, counterName); - expect(counterState?.count).toBe(2); - dispatch(experimentBufferMultiplyByCountFromConcepts(), { - iterateStage: true, - }); - }), - createStage((concepts, _dispatch, changes) => { - const counterState = selectState(concepts, counterName); - if (changes.length > 0) { - expect(counterState?.count).toBe(16); - setTimeout(() => { - plan.conclude(); - axium.close(); - done(); - }, 10); - } - }, {selectors: [counterSelectCount], beat: 200}), - createStage(() => { - plan.conclude(); - }) - ]); -}); - -test('Buffer method with concept towards final multiply of count', (done) => { - const experiment = createExperimentConcept(createExperimentState(), [experimentAsyncBufferMultiplyByCountFromConceptsQuality]); - const axium = createAxium('Experiment method buffer defer multiply', [createCounterConcept(), experiment], { - // logActionStream: true - }); - const plan = axium.plan('Experiment buffer multiply by 2 from concept state after 10ms', [ - stageWaitForOpenThenIterate(() => axiumKick()), - createStage((_, dispatch) => { - dispatch(counterSetCount({ - newCount: 2 - }), { - iterateStage: true, - }); - }), - createStage((concepts, dispatch) => { - const counterState = selectState(concepts, counterName); - expect(counterState?.count).toBe(2); - dispatch(experimentAsyncBufferMultiplyByCountFromConcepts(), { - iterateStage: true, - }); - }), - createStage((concepts, dispatch) => { - const counterState = selectState(concepts, counterName); - expect(counterState?.count).toBe(2); - dispatch(experimentAsyncBufferMultiplyByCountFromConcepts(), { - iterateStage: true, - }); - }), - createStage((concepts, dispatch) => { - const counterState = selectState(concepts, counterName); - expect(counterState?.count).toBe(2); - dispatch(experimentAsyncBufferMultiplyByCountFromConcepts(), { - iterateStage: true, - }); - }), - createStage((concepts, _dispatch, changes) => { - const counterState = selectState(concepts, counterName); - console.log('CHECK STATE', counterState); - if (changes.length > 0) { - expect(counterState?.count).toBe(16); - setTimeout(() => { - plan.conclude(); - axium.close(); - done(); - }, 10); - } - }, {selectors: [counterSelectCount], beat: 200}), - createStage(() => { - plan.conclude(); - }) - ]); - // axium.subscribe(c => { - // const s = getAxiumState(c); - // console.log(s.head, s.body, s.tail); - // }); -}); -/*#>*/ \ No newline at end of file diff --git a/src/test/bufferMethods/qualities/asyncBufferMultiplyByCountFromConceptsAction.quality.ts b/src/test/bufferMethods/qualities/asyncBufferMultiplyByCountFromConceptsAction.quality.ts deleted file mode 100644 index 9671a8f..0000000 --- a/src/test/bufferMethods/qualities/asyncBufferMultiplyByCountFromConceptsAction.quality.ts +++ /dev/null @@ -1,33 +0,0 @@ -/*<$ -For the asynchronous graph programming framework Stratimux and Experiment Concept, generate a method that will buffer asynchronously -the dispatch of an action assigned to payload. -$>*/ -/*<#*/ -import { defaultReducer } from '../../../model/concept'; -import { createActionNode, createStrategy, strategyBegin, } from '../../../model/actionStrategy'; -import { createQualitySet, } from '../../../model/quality'; -import { selectState } from '../../../model/selector'; -import { CounterState, counterName } from '../../../concepts/counter/counter.concept'; -import { counterMultiply } from '../../../concepts/counter/qualities/multiply.quality'; -import { createAsyncMethodBufferWithConcepts } from '../../../model/method'; - -export const [ - experimentAsyncBufferMultiplyByCountFromConcepts, - experimentAsyncBufferMultiplyByCountFromConceptsType, - experimentAsyncBufferMultiplyByCountFromConceptsQuality -] = createQualitySet({ - type: 'Experiment will asynchronously buffer multiply count using concepts accessing counter state', - reducer: defaultReducer, - methodCreator: (c, s) => createAsyncMethodBufferWithConcepts((controller, _, concepts) => { - setTimeout(() => { - const counterState = selectState(concepts, counterName); - controller.fire(strategyBegin(createStrategy({ - initialNode: createActionNode(counterMultiply({ - by: counterState?.count as number - })), - topic: 'AsyncBuffered Action Topic' - }))); - }, 50); - }, c, s, 10) -}); -/*#>*/ \ No newline at end of file diff --git a/src/test/bufferMethods/qualities/bufferMultiplyByCountFromConceptsAction.quality.ts b/src/test/bufferMethods/qualities/bufferMultiplyByCountFromConceptsAction.quality.ts deleted file mode 100644 index a31a480..0000000 --- a/src/test/bufferMethods/qualities/bufferMultiplyByCountFromConceptsAction.quality.ts +++ /dev/null @@ -1,31 +0,0 @@ -/*<$ -For the asynchronous graph programming framework Stratimux and Experiment Concept, generate a method that will buffer -the dispatch of an action assigned to payload. -$>*/ -/*<#*/ -import { defaultReducer } from '../../../model/concept'; -import { createMethodBufferWithConcepts } from '../../../model/method'; -import { createActionNode, createStrategy, strategyBegin, } from '../../../model/actionStrategy'; -import { createQualitySet } from '../../../model/quality'; -import { selectState } from '../../../model/selector'; -import { CounterState, counterName } from '../../../concepts/counter/counter.concept'; -import { counterMultiply } from '../../../concepts/counter/qualities/multiply.quality'; - -export const [ - experimentBufferMultiplyByCountFromConcepts, - experimentBufferMultiplyByCountFromConceptsType, - experimentBufferMultiplyByCountFromConceptsQuality -] = createQualitySet({ - type: 'Experiment will buffer multiply count using concepts accessing counter state', - reducer: defaultReducer, - methodCreator: (c, s) => createMethodBufferWithConcepts((_, concepts) => { - const counterState = selectState(concepts, counterName); - return strategyBegin(createStrategy({ - initialNode: createActionNode(counterMultiply({ - by: counterState?.count as number - })), - topic: 'Buffered Action Topic' - })); - }, c, s, 10) -}); -/*#>*/ \ No newline at end of file diff --git a/src/test/bufferMethods/qualities/bufferSomeAction.quality.ts b/src/test/bufferMethods/qualities/bufferSomeAction.quality.ts deleted file mode 100644 index f61e68f..0000000 --- a/src/test/bufferMethods/qualities/bufferSomeAction.quality.ts +++ /dev/null @@ -1,32 +0,0 @@ -/*<$ -For the asynchronous graph programming framework Stratimux and Experiment Concept, generate a method that will buffer -the dispatch of an action assigned to payload. -$>*/ -/*<#*/ -import { defaultReducer } from '../../../model/concept'; -import { createMethodBuffer } from '../../../model/method'; -import { createActionNode, createStrategy, strategyBegin, } from '../../../model/actionStrategy'; -import { createQualitySetWithPayload } from '../../../model/quality'; -import { Action } from '../../../model/action'; -import { selectPayload } from '../../../model/selector'; - -type ExperimentBufferNextActionPayload = { - action: Action -} - -export const [ - experimentBufferNextAction, - experimentBufferNextActionType, - experimentBufferNextActionQuality -] = createQualitySetWithPayload({ - type: 'Experiment will buffer incoming actions for a set duration', - reducer: defaultReducer, - methodCreator: () => createMethodBuffer((action) => { - const act = selectPayload(action).action; - return strategyBegin(createStrategy({ - initialNode: createActionNode(act), - topic: 'Buffered Action Topic' - })); - }, 10) -}); -/*#>*/ \ No newline at end of file