diff --git a/README.md b/README.md index 97c8849..ed1f624 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,8 @@ 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) +### v0.1.53 4/23/24 +* Added createQualitySet and createQualitySetWithPayload to reduce some boilerplate. ### v0.1.52 Patch 4/03/24 * Quick pass updating documentation * Synced up createAxium, etc... To properly allow for the axium to log actions incoming in the action stream if set. @@ -150,7 +152,7 @@ import { MethodCreator, Action, prepareActionCreator, - createQuality, + createQualitySetWithPayload, UnifiedSubject, createMethodWithState, strategySuccess, @@ -159,17 +161,19 @@ import { } from 'stratimux'; import { UXState } from '../uX.concept'; -export const uXqOfUXType = 'uX allows for easy selection of your qualities, qOfUX is your quality, and Type is the distinction'; -export const uXqOfUX = prepareActionCreator(uXqOfUXType); -export type uXqOfUxField = { - state: UXState -}; - function getRandomRange(min: number, max: number) { return Math.random() * (max - min) + min; } -const uXqOfUXCreator: MethodCreator = (concepts$?: Subject, semaphore?: number) => +export type uXqOfUxField = { + state: UXState +}; + +// [ActionCreator/ActionCreatorWithPayload, ActionType, Quality] +export const [uXqOfUX, uXqOfUXType, uXqOfUXQuality] = createQualitySetWithPayload({ + type: 'uX allows for easy selection of your qualities, qOfUX is your quality, and Type is the distinction', + reducer: (state: UXState) => ({...state}), + methodCreator: (concepts$?: Subject, semaphore?: number) => // Only if you need to access state, otherwise createMethodWithState((action, state) => { if (action.strategy) { @@ -186,24 +190,13 @@ const uXqOfUXCreator: MethodCreator = (concepts$?: Subject, semaphore? } } return action; - }, concepts$ as UnifiedSubject, semaphore as number); - -function uXqOfUXReducer(state: UXState, _: Action): UXState { - return { - ...state, - }; -} - -export const uXqOfUXQuality = createQuality( - uXqOfUXType, - uXqOfUXReducer, - uXqOfUXCreator -); + }, concepts$ as UnifiedSubject, semaphore as number) +}); /* Below are the default functions available for your quality */ // export const qOfUXQuality = createQuality( // qOfUXType, // defaultReducer(Informs)/nullReducer(Doesn't Inform), -// The method is optional and is an advanced behavior +// The method is optional and is an advanced behavior enabling the quality to be used in an ActionStrategy // defaultMethodCreator // ); ``` diff --git a/SpatialOwnership.md b/SpatialOwnership.md index 6d2579a..e5007b8 100644 --- a/SpatialOwnership.md +++ b/SpatialOwnership.md @@ -41,8 +41,8 @@ export type OwnershipState = { * backTrack - To be used within an ActionStrategy's failureNode. This will allow your strategy to return to the previous node while appending the designated failure message to the action list, without setting its own. * clearPayloadStubs - To be used within your own qualities and utilized within a strategy if it no longer requires a specific lock. Setting some stubs to the payload of this action will clear those stubs from the ownershipLedger. Note that you would have to clear these stubs from your strategy if present. * clearStrategyStubsFromLedgerAndSelf - To be used within a strategy, this will clear the current strategies stubs from the ledger and set its current stubs to undefined. -* clearPendingActions - Will simply clear the pendingAction list. Note that the stubs would still exist and one should use this in combination with clearPayloadStubs to avoid having to wait for expiration. -* clearPendingActionsOfStrategyTopic - Will clear any ActionStrategies of a set payload topic string from pendingAction. +* ownershipClearPendingActions - Will simply clear the pendingAction list. Note that the stubs would still exist and one should use this in combination with clearPayloadStubs to avoid having to wait for expiration. +* ownershipClearPendingActionsOfStrategyTopic - Will clear any ActionStrategies of a set payload topic string from pendingAction. * resetOwnershipLedger - This will do a dumb reset of the currently loaded ownershipLedger ### Internal Ownership Qualities diff --git a/package.json b/package.json index 9c00050..19dea95 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "stratimux", "license": "GPL-3.0", - "version": "0.1.52", + "version": "0.1.53", "description": "Unified Turing Machine", "main": "dist/index.js", "module": "dist/index.mjs", diff --git a/src/concepts/axium/qualities/addConceptsFromQue.quality.ts b/src/concepts/axium/qualities/addConceptsFromQue.quality.ts index 815d67e..c688585 100644 --- a/src/concepts/axium/qualities/addConceptsFromQue.quality.ts +++ b/src/concepts/axium/qualities/addConceptsFromQue.quality.ts @@ -3,49 +3,18 @@ For the asynchronous graph programming framework Stratimux and Axium Concept, generate a quality that will add concepts within the addConceptQue into the Axium's Concepts. $>*/ /*<#*/ -import { Observable, Subject, Subscriber, catchError } from 'rxjs'; -import { defaultMethodCreator, qualityToString } from '../../../model/concept'; +import { defaultMethodCreator } from '../../../model/concept'; import { AxiumState } from '../axium.concept'; -import { Action, ActionType, prepareActionCreator } from '../../../model/action'; -import { createQuality } from '../../../model/concept'; -import { blockingMethodSubscription } from '../../../model/axium'; +import { createQualitySet } from '../../../model/quality'; -export const axiumAddConceptFromQueType: ActionType = 'Add Concepts from Axium Concept Que'; -export const axiumAddConceptFromQue = prepareActionCreator(axiumAddConceptFromQueType); - -function axiumAddConceptsFromQueReducer(state: AxiumState, action: Action) { - // const methodSubscribers = state.methodSubscribers; - // const addConceptsQue = state.addConceptQue; - // addConceptsQue.forEach((concept) => { - // concept.qualities.forEach(quality => { - // if (quality.methodCreator) { - // [quality.method, quality.subject] = quality.methodCreator(state.concepts$, concept.semaphore); - // quality.method.pipe( - // catchError((err: unknown, caught: Observable) => { - // if (state.logging) { - // console.error('METHOD ERROR', err); - // } - // return caught; - // })); - // quality.toString = qualityToString(quality); - // const methodSub = quality.method.subscribe((act: Action) => { - // const action$ = state.action$ as Subject; - // blockingMethodSubscription(action$, act); - // }) as Subscriber; - // methodSubscribers.push({name: concept.name, subscription: methodSub}); - // } - // }); - // }); - return { - ...state, - // methodSubscribers, - addConceptQue: [] - }; -} - -export const axiumAddConceptsFromQueQuality = createQuality( - axiumAddConceptFromQueType, - axiumAddConceptsFromQueReducer, - defaultMethodCreator -); +export const [axiumAddConceptFromQue, axiumAddConceptFromQueType, axiumAddConceptsFromQueQuality] = createQualitySet({ + type: 'Add Concepts from Axium Concept Que', + reducer: (state: AxiumState, action) => { + return { + ...state, + addConceptQue: [] + }; + }, + methodCreator: defaultMethodCreator +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/axium/qualities/appendActionListToDialog.quality.ts b/src/concepts/axium/qualities/appendActionListToDialog.quality.ts index 9f210b6..cdecfc2 100644 --- a/src/concepts/axium/qualities/appendActionListToDialog.quality.ts +++ b/src/concepts/axium/qualities/appendActionListToDialog.quality.ts @@ -3,45 +3,43 @@ For the asynchronous graph programming framework Stratimux and Axium Concept, ge into the dialog state property. $>*/ /*<#*/ -import { Action, ActionType, prepareActionWithPayloadCreator } from '../../../model/action'; -import { createQuality } from '../../../model/concept'; import { AxiumState } from '../axium.concept'; import { selectPayload } from '../../../model/selector'; +import { createQualitySetWithPayload } from '../../../model/quality'; export type AppendActionListToDialogPayload = { actionList: Array; strategyTopic: string; strategyData: unknown; } -export const axiumAppendActionListToDialogType: ActionType = 'append Action List to Axium\'s Dialog'; -export const axiumAppendActionListToDialog = - prepareActionWithPayloadCreator(axiumAppendActionListToDialogType); -export function axiumAppendActionListToDialogReducer(state: AxiumState, action: Action): AxiumState { - const payload = selectPayload(action); - let newDialog = ''; - if (state.storeDialog) { - payload.actionList.forEach(str => {newDialog += str + ' ';}); - if (state.logging) { - console.log(newDialog); +export const [ + axiumAppendActionListToDialog, + axiumAppendActionListToDialogType, + axiumAppendActionListToDialogQuality +] = createQualitySetWithPayload({ + type: 'append Action List to Axium\'s Dialog', + reducer: (state: AxiumState, action) => { + const payload = selectPayload(action); + let newDialog = ''; + if (state.storeDialog) { + payload.actionList.forEach(str => {newDialog += str + ' ';}); + if (state.logging) { + console.log(newDialog); + } + return { + ...state, + dialog: state.dialog + newDialog, + lastStrategy: payload.strategyTopic, + lastStrategyData: payload.strategyData, + lastStrategyDialog: newDialog + }; } return { ...state, - dialog: state.dialog + newDialog, lastStrategy: payload.strategyTopic, lastStrategyData: payload.strategyData, - lastStrategyDialog: newDialog }; } - return { - ...state, - lastStrategy: payload.strategyTopic, - lastStrategyData: payload.strategyData, - }; -} - -export const axiumAppendActionListToDialogQuality = createQuality( - axiumAppendActionListToDialogType, - axiumAppendActionListToDialogReducer, -); +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/axium/qualities/appendConceptsToAddQue.quality.ts b/src/concepts/axium/qualities/appendConceptsToAddQue.quality.ts index a78958b..104242e 100644 --- a/src/concepts/axium/qualities/appendConceptsToAddQue.quality.ts +++ b/src/concepts/axium/qualities/appendConceptsToAddQue.quality.ts @@ -5,31 +5,29 @@ $>*/ /*<#*/ import { Concept, defaultMethodCreator } from '../../../model/concept'; import { AxiumState } from '../axium.concept'; -import { Action, ActionType, prepareActionWithPayloadCreator } from '../../../model/action'; -import { createQuality } from '../../../model/concept'; import { selectPayload } from '../../../model/selector'; +import { createQualitySetWithPayload } from '../../../model/quality'; export type AxiumAppendConceptsToAddQuePayload = { concepts: Concept[] } -export const axiumAppendConceptsToAddQueType: ActionType = 'append Concepts to Axium\'s Add Concept Que'; -export const axiumAppendConceptsToAddQue = - prepareActionWithPayloadCreator(axiumAppendConceptsToAddQueType); -export function axiumAppendConceptsToAddQueReducer(state: AxiumState, action: Action) { - const payload = selectPayload(action); - const addConceptQue = [ - ...payload.concepts - ]; - return { - ...state, - addConceptQue, - }; -} - -export const axiumAppendConceptsToAddQueQuality = createQuality( +export const [ + axiumAppendConceptsToAddQue, axiumAppendConceptsToAddQueType, - axiumAppendConceptsToAddQueReducer, - defaultMethodCreator -); + axiumAppendConceptsToAddQueQuality +] = createQualitySetWithPayload({ + type: 'append Concepts to Axium\'s Add Concept Que', + reducer: (state: AxiumState, action) => { + const payload = selectPayload(action); + const addConceptQue = [ + ...payload.concepts + ]; + return { + ...state, + addConceptQue, + }; + }, + methodCreator: defaultMethodCreator +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/axium/qualities/appendConceptsToRemoveQue.quality.ts b/src/concepts/axium/qualities/appendConceptsToRemoveQue.quality.ts index d57d230..a2756a4 100644 --- a/src/concepts/axium/qualities/appendConceptsToRemoveQue.quality.ts +++ b/src/concepts/axium/qualities/appendConceptsToRemoveQue.quality.ts @@ -5,33 +5,31 @@ $>*/ /*<#*/ import { Concept, defaultMethodCreator } from '../../../model/concept'; import { AxiumState } from '../axium.concept'; -import { Action, ActionType, prepareActionWithPayloadCreator } from '../../../model/action'; -import { createQuality } from '../../../model/concept'; import { selectPayload } from '../../../model/selector'; +import { createQualitySetWithPayload } from '../../../model/quality'; export type AxiumAppendConceptsToRemoveQuePayload = { concepts: Concept[] } -export const axiumAppendConceptsToRemoveQueType: ActionType = 'append Concepts to Axium\'s Remove Concept Que'; -export const axiumAppendConceptsToRemoveQue = - prepareActionWithPayloadCreator(axiumAppendConceptsToRemoveQueType); -export function axiumAppendConceptsToRemoveQueReducer(state: AxiumState, action: Action) { - const payload = selectPayload(action); - let removeQue = state.removeConceptQue; - removeQue = [ - ...removeQue, - ...payload.concepts - ]; - return { - ...state, - removeConceptQue: removeQue - }; -} - -export const axiumAppendConceptsToRemoveQueQuality = createQuality( +export const [ + axiumAppendConceptsToRemoveQue, axiumAppendConceptsToRemoveQueType, - axiumAppendConceptsToRemoveQueReducer, - defaultMethodCreator -); + axiumAppendConceptsToRemoveQueQuality +] = createQualitySetWithPayload({ + type: 'append Concepts to Axium\'s Remove Concept Que', + reducer: (state: AxiumState, action) => { + const payload = selectPayload(action); + let removeQue = state.removeConceptQue; + removeQue = [ + ...removeQue, + ...payload.concepts + ]; + return { + ...state, + removeConceptQue: removeQue + }; + }, + methodCreator: defaultMethodCreator +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/axium/qualities/badAction.quality.ts b/src/concepts/axium/qualities/badAction.quality.ts index 881efe2..ee26eaa 100644 --- a/src/concepts/axium/qualities/badAction.quality.ts +++ b/src/concepts/axium/qualities/badAction.quality.ts @@ -5,32 +5,31 @@ is currently not loaded, part of the wrong generation, expired, etc... If state of the bad action that was received. $>*/ /*<#*/ -import { Action, ActionType, prepareActionWithPayloadCreator } from '../../../model/action'; -import { createQuality } from '../../../model/concept'; +import { Action } from '../../../model/action'; +import { createQualitySetWithPayload } from '../../../model/quality'; import { selectPayload } from '../../../model/selector'; import { AxiumState } from '../axium.concept'; export type AxiumBadActionPayload = { badActions: Action[], } -export const axiumBadActionType: ActionType = 'Axium received a Bad Action'; -export const axiumBadAction = prepareActionWithPayloadCreator(axiumBadActionType); - -export function axiumBadActionReducer(state: AxiumState, action: Action) { - const payload = selectPayload(action).badActions; - if (state.logging) { - console.log('Axium Received a Bad Action: ', action); - } - return { - ...state, - badActions: [ - ...state.badActions, ...payload - ] - }; -} - -export const axiumBadActionQuality = createQuality( +export const [ + axiumBadAction, axiumBadActionType, - axiumBadActionReducer -); + axiumBadActionQuality +] = createQualitySetWithPayload({ + type: 'Axium received a Bad Action', + reducer: (state: AxiumState, action) => { + const payload = selectPayload(action).badActions; + if (state.logging) { + console.log('Axium Received a Bad Action: ', action); + } + return { + ...state, + badActions: [ + ...state.badActions, ...payload + ] + }; + } +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/axium/qualities/clearBadActionTypeFromBadActionList.quality.ts b/src/concepts/axium/qualities/clearBadActionTypeFromBadActionList.quality.ts index 58829fe..149ef5a 100644 --- a/src/concepts/axium/qualities/clearBadActionTypeFromBadActionList.quality.ts +++ b/src/concepts/axium/qualities/clearBadActionTypeFromBadActionList.quality.ts @@ -4,29 +4,28 @@ generate a quality that will clear a specified action type from the state's badA This list is utilized by future on the fly error correction for handling generated qualities for an embodied artificial intelligence. $>*/ /*<#*/ -import { defaultMethodCreator, createQuality } from '../../../model/concept'; -import { Action, ActionType, prepareActionWithPayloadCreator } from '../../../model/action'; +import { defaultMethodCreator } from '../../../model/concept'; +import { ActionType } from '../../../model/action'; import { AxiumState } from '../axium.concept'; import { selectPayload } from '../../../model/selector'; +import { createQualitySetWithPayload } from '../../../model/quality'; export type AxiumClearBadActionTypeFromBadActionListPayload = { actionType: ActionType }; -export const axiumClearBadActionTypeFromBadActionListType: ActionType = 'clear ActionType from Axium\'s badAction list'; -export const axiumClearBadActionTypeFromBadActionList = - prepareActionWithPayloadCreator(axiumClearBadActionTypeFromBadActionListType); - -function axiumClearBadActionTypeFromBadActionListReducer(state: AxiumState, action: Action): AxiumState { - const actionType = selectPayload(action).actionType; - return { - ...state, - badActions: state.badActions.filter(act => act.type !== actionType), - }; -} - -export const axiumClearBadActionTypeFromBadActionListQuality = createQuality( +export const [ + axiumClearBadActionTypeFromBadActionList, axiumClearBadActionTypeFromBadActionListType, - axiumClearBadActionTypeFromBadActionListReducer, - defaultMethodCreator, -); + axiumClearBadActionTypeFromBadActionListQuality +] = createQualitySetWithPayload({ + type: 'clear ActionType from Axium\'s badAction list', + reducer: (state: AxiumState, action) => { + const {actionType} = selectPayload(action); + return { + ...state, + badActions: state.badActions.filter(act => act.type !== actionType), + }; + }, + methodCreator: defaultMethodCreator +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/axium/qualities/clearBadPlanFromBadPlanList.quality.ts b/src/concepts/axium/qualities/clearBadPlanFromBadPlanList.quality.ts index 7b1c4d1..e7f1311 100644 --- a/src/concepts/axium/qualities/clearBadPlanFromBadPlanList.quality.ts +++ b/src/concepts/axium/qualities/clearBadPlanFromBadPlanList.quality.ts @@ -4,29 +4,28 @@ generate a quality that will clear a specified plan from the badPlan list on sta This allows for generated plans via an embodied artificial intelligence to error correct on the fly for any poorly generated plans. $>*/ /*<#*/ -import { defaultMethodCreator, createQuality } from '../../../model/concept'; -import { Action, ActionType, prepareActionWithPayloadCreator } from '../../../model/action'; +import { defaultMethodCreator } from '../../../model/concept'; import { AxiumState } from '../axium.concept'; import { selectPayload } from '../../../model/selector'; +import { createQualitySet } from '../../../model/quality'; export type AxiumClearBadPlanFromBadPlanListPayload = { title: string }; -export const axiumClearBadPlanFromBadPlanListType: ActionType = 'clear Plan Topic from Axium\'s badPlan list'; -export const axiumClearBadPlanFromBadPlanList = - prepareActionWithPayloadCreator(axiumClearBadPlanFromBadPlanListType); -function axiumClearBadPlanFromBadPlanListReducer(state: AxiumState, action: Action): AxiumState { - const title = selectPayload(action).title; - return { - ...state, - badPlans: state.badPlans.filter(act => act.title !== title), - }; -} - -export const axiumClearBadPlanFromBadPlanListQuality = createQuality( - axiumClearBadPlanFromBadPlanListType, - axiumClearBadPlanFromBadPlanListReducer, - defaultMethodCreator, -); +export const [ + axiumClearBadPlanFromBadPlanList, + axiumClearBadPlanFromBadPlanListQualityType, + axiumClearBadPlanFromBadPlanListQuality +] = createQualitySet({ + type: 'clear Plan Topic from Axium\'s badPlan list', + reducer: (state: AxiumState, action) => { + const {title} = selectPayload(action); + return { + ...state, + badPlans: state.badPlans.filter(act => act.title !== title), + }; + }, + methodCreator: defaultMethodCreator +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/axium/qualities/clearBadStrategyTopicFromBadActionList.quality.ts b/src/concepts/axium/qualities/clearBadStrategyTopicFromBadActionList.quality.ts index 0a9df39..0691189 100644 --- a/src/concepts/axium/qualities/clearBadStrategyTopicFromBadActionList.quality.ts +++ b/src/concepts/axium/qualities/clearBadStrategyTopicFromBadActionList.quality.ts @@ -4,36 +4,34 @@ generate a quality that will remove a strategies topic from state's badAction li This allows for an Artificial Intelligence that is embodying Stratimux to correct generated strategies on the fly. $>*/ /*<#*/ -import { defaultMethodCreator, createQuality } from '../../../model/concept'; -import { Action, ActionType, prepareActionWithPayloadCreator } from '../../../model/action'; +import { defaultMethodCreator } from '../../../model/concept'; import { AxiumState } from '../axium.concept'; import { selectPayload } from '../../../model/selector'; +import { createQualitySetWithPayload } from '../../../model/quality'; export type AxiumClearBadStrategyTopicFromBadActionListPayload = { topic: string }; -export const axiumClearBadStrategyTopicFromBadActionListType: ActionType = 'clear Strategy Topic from Axium\'s badAction list'; -export const axiumClearBadStrategyTopicFromBadActionList = - prepareActionWithPayloadCreator(axiumClearBadStrategyTopicFromBadActionListType); - -function axiumClearBadStrategyTopicFromBadActionListReducer(state: AxiumState, action: Action): AxiumState { - const strategyTopic = selectPayload(action).topic; - const badActions = state.badActions.filter(act => { - if (act.strategy && act.strategy.topic !== strategyTopic) { - return true; - } else { - return false; - } - }); - return { - ...state, - badActions, - }; -} - -export const axiumClearBadStrategyTopicFromBadActionListQuality = createQuality( +export const [ + axiumClearBadStrategyTopicFromBadActionList, axiumClearBadStrategyTopicFromBadActionListType, - axiumClearBadStrategyTopicFromBadActionListReducer, - defaultMethodCreator, -); + axiumClearBadStrategyTopicFromBadActionListQuality +] = createQualitySetWithPayload({ + type: 'clear Strategy Topic from Axium\'s badAction list', + reducer: (state: AxiumState, action) => { + const {topic} = selectPayload(action); + const badActions = state.badActions.filter(act => { + if (act.strategy && act.strategy.topic !== topic) { + return true; + } else { + return false; + } + }); + return { + ...state, + badActions, + }; + }, + methodCreator: defaultMethodCreator +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/axium/qualities/clearDialog.quality.ts b/src/concepts/axium/qualities/clearDialog.quality.ts index e0dd65d..28ee0ea 100644 --- a/src/concepts/axium/qualities/clearDialog.quality.ts +++ b/src/concepts/axium/qualities/clearDialog.quality.ts @@ -3,23 +3,22 @@ For the asynchronous graph programming framework Stratimux and Axium Concept, generate a quality that will clear the state's dialog. $>*/ /*<#*/ -import { defaultMethodCreator, createQuality } from '../../../model/concept'; -import { Action, ActionType, prepareActionCreator } from '../../../model/action'; +import { defaultMethodCreator } from '../../../model/concept'; import { AxiumState } from '../axium.concept'; +import { createQualitySet } from '../../../model/quality'; -export const axiumClearDialogType: ActionType = 'clear Axium Dialog'; -export const axiumClearDialog = prepareActionCreator(axiumClearDialogType); - -export function axiumClearDialogReducer(state: AxiumState, action: Action) { - return { - ...state, - dialog: '', - }; -} - -export const axiumClearDialogQuality = createQuality( +export const [ + axiumClearDialog, axiumClearDialogType, - axiumClearDialogReducer, - defaultMethodCreator, -); + axiumClearDialogQuality +] = createQualitySet({ + type: 'clear Axium Dialog', + reducer: (state: AxiumState) => { + return { + ...state, + dialog: '', + }; + }, + methodCreator: defaultMethodCreator +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/axium/qualities/close.quality.ts b/src/concepts/axium/qualities/close.quality.ts index 7471fe4..db62b63 100644 --- a/src/concepts/axium/qualities/close.quality.ts +++ b/src/concepts/axium/qualities/close.quality.ts @@ -8,6 +8,7 @@ import { createQuality } from '../../../model/concept'; import { Action, ActionType, prepareActionWithPayloadCreator } from '../../../model/action'; import { AxiumState } from '../axium.concept'; import { selectPayload } from '../../../model/selector'; +import { createQualitySet, createQualitySetWithPayload } from '../../../model/quality'; /** * @parm exit - If set to true, will exit the current process. @@ -15,30 +16,29 @@ import { selectPayload } from '../../../model/selector'; export type AxiumClosePayload = { exit: boolean }; -export const axiumCloseType: ActionType = 'Close Axium'; -export const axiumClose = prepareActionWithPayloadCreator(axiumCloseType); - -export function axiumCloseReducer(state: AxiumState, _action: Action): AxiumState { - const {exit} = selectPayload(_action); - state.generalSubscribers.forEach(named => named.subscription.unsubscribe()); - state.methodSubscribers.forEach(named => named.subscription.unsubscribe()); - state.stagePlanners.forEach(named => named.conclude()); - state.action$.complete(); - state.concepts$.complete(); - state.actionConcepts$.complete(); - if (exit) { - process.exit(); - } - return { - ...state, - methodSubscribers: [], - generalSubscribers: [], - stagePlanners: [], - }; -} - -export const axiumCloseQuality = createQuality( +export const [ + axiumClose, axiumCloseType, - axiumCloseReducer -); + axiumCloseQuality +] = createQualitySetWithPayload({ + type: 'Close Axium', + reducer: (state: AxiumState, action) => { + const {exit} = selectPayload(action); + state.generalSubscribers.forEach(named => named.subscription.unsubscribe()); + state.methodSubscribers.forEach(named => named.subscription.unsubscribe()); + state.stagePlanners.forEach(named => named.conclude()); + state.action$.complete(); + state.concepts$.complete(); + state.actionConcepts$.complete(); + if (exit) { + process.exit(); + } + return { + ...state, + methodSubscribers: [], + generalSubscribers: [], + stagePlanners: [], + }; + } +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/axium/qualities/initializePrinciples.quality.ts b/src/concepts/axium/qualities/initializePrinciples.quality.ts index fa163d4..964843d 100644 --- a/src/concepts/axium/qualities/initializePrinciples.quality.ts +++ b/src/concepts/axium/qualities/initializePrinciples.quality.ts @@ -6,57 +6,56 @@ $>*/ import { Subject, Subscriber } from 'rxjs'; import { Concept, Concepts, defaultMethodCreator, forEachConcept } from '../../../model/concept'; import { createPrinciple$ } from '../../../model/principle'; -import { Action, ActionType, prepareActionWithPayloadCreator } from '../../../model/action'; +import { Action, } from '../../../model/action'; import { AxiumState, axiumName } from '../axium.concept'; -import { createQuality } from '../../../model/concept'; import { UnifiedSubject } from '../../../model/stagePlanner'; import { selectPayload } from '../../../model/selector'; +import { createQualitySetWithPayload } from '../../../model/quality'; export type AxiumInitializePrinciplesPayload = { concepts: Concepts; } -export const axiumInitializePrinciplesType: ActionType = 'initialize Principles and set new Subscribers to General Subscribers list'; -export const axiumInitializePrinciples = - prepareActionWithPayloadCreator(axiumInitializePrinciplesType); -export function axiumInitializePrinciplesReducer(state: AxiumState, _action: Action): AxiumState { - const payload = selectPayload(_action); - const concepts = payload.concepts; - let conceptCounter = state.conceptCounter; - const action$ = state.action$ as Subject; - const concepts$ = state.concepts$ as UnifiedSubject; - const principleSubscribers = state.generalSubscribers; - forEachConcept(concepts ,((concept: Concept, semaphore) => { - if (concept.name === axiumName && concept.principles) { - concept.principles.forEach(principle => { - const observable = createPrinciple$(principle, concepts, state.concepts$, semaphore as number); - principleSubscribers.push({ - name: concept.name, - subscription: observable.subscribe((action: Action) => action$.next(action)) as Subscriber, +export const [ + axiumInitializePrinciples, + axiumInitializePrinciplesType, + axiumInitializePrinciplesQuality +] = createQualitySetWithPayload({ + type: 'initialize Principles and set new Subscribers to General Subscribers list', + reducer: (state: AxiumState, act) => { + const payload = selectPayload(act); + const concepts = payload.concepts; + let conceptCounter = state.conceptCounter; + const action$ = state.action$ as Subject; + const concepts$ = state.concepts$ as UnifiedSubject; + const principleSubscribers = state.generalSubscribers; + forEachConcept(concepts ,((concept: Concept, semaphore) => { + if (concept.name === axiumName && concept.principles) { + concept.principles.forEach(principle => { + const observable = createPrinciple$(principle, concepts, state.concepts$, semaphore as number); + principleSubscribers.push({ + name: concept.name, + subscription: observable.subscribe((action: Action) => action$.next(action)) as Subscriber, + }); }); - }); - conceptCounter += 1; - } else if (concept.principles) { - concept.principles.forEach(principle => { - const observable = createPrinciple$(principle, concepts, concepts$, semaphore as number); - principleSubscribers.push({ - name: concept.name, - subscription: observable.subscribe((action: Action) => action$.next(action)) as Subscriber, + conceptCounter += 1; + } else if (concept.principles) { + concept.principles.forEach(principle => { + const observable = createPrinciple$(principle, concepts, concepts$, semaphore as number); + principleSubscribers.push({ + name: concept.name, + subscription: observable.subscribe((action: Action) => action$.next(action)) as Subscriber, + }); }); - }); - conceptCounter += 1; - } - })); - return { - ...state, - principleSubscribers, - conceptCounter, - }; -} - -export const axiumInitializePrinciplesQuality = createQuality( - axiumInitializePrinciplesType, - axiumInitializePrinciplesReducer, - defaultMethodCreator -); + conceptCounter += 1; + } + })); + return { + ...state, + principleSubscribers, + conceptCounter, + }; + }, + methodCreator: defaultMethodCreator +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/axium/qualities/kick.quality.ts b/src/concepts/axium/qualities/kick.quality.ts index 2bf429a..a79fc5e 100644 --- a/src/concepts/axium/qualities/kick.quality.ts +++ b/src/concepts/axium/qualities/kick.quality.ts @@ -5,15 +5,11 @@ Likewise this quality is used to kick the axium into gear if currently resting d $>*/ /*<#*/ import { defaultMethodCreator, defaultReducer } from '../../../model/concept'; -import { ActionType, prepareActionCreator } from '../../../model/action'; -import { createQuality } from '../../../model/concept'; +import { createQualitySet } from '../../../model/quality'; -export const axiumKickType: ActionType = 'Kick Axium'; -export const axiumKick = prepareActionCreator(axiumKickType); - -export const axiumKickQuality = createQuality( - axiumKickType, - defaultReducer, - defaultMethodCreator -); +export const [axiumKick, axiumKickType, axiumKickQuality] = createQualitySet({ + type: 'Kick Axium', + reducer: defaultReducer, + methodCreator: defaultMethodCreator +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/axium/qualities/log.quality.ts b/src/concepts/axium/qualities/log.quality.ts index 8cfc4ed..e717b77 100644 --- a/src/concepts/axium/qualities/log.quality.ts +++ b/src/concepts/axium/qualities/log.quality.ts @@ -3,27 +3,25 @@ For the asynchronous graph programming framework Stratimux and Axium Concept, ge This is used to trouble shoot strategies or simply notify the log of different states. $>*/ /*<#*/ -import { MethodCreator, defaultReducer, nullReducer } from '../../../model/concept'; -import { ActionType, prepareActionCreator } from '../../../model/action'; -import { createQuality } from '../../../model/concept'; +import { nullReducer } from '../../../model/concept'; import { strategySuccess } from '../../../model/actionStrategy'; import { createMethod } from '../../../model/method'; +import { createQualitySet } from '../../../model/quality'; -export const axiumLogType: ActionType = 'logged a message passed to Axium'; -export const axiumLog = prepareActionCreator(axiumLogType); - -export const axiumLogMethodCreator: MethodCreator = () => createMethod((action) => { - console.log('Logging: ', action); - if (action.strategy) { - return strategySuccess(action.strategy); - } else { - return action; - } -}); - -export const axiumLogQuality = createQuality( +export const [ + axiumLog, axiumLogType, - nullReducer, - axiumLogMethodCreator, -); + axiumLogQuality +] = createQualitySet({ + type: 'logged a message passed to Axium', + reducer: nullReducer, + methodCreator: () => createMethod((action) => { + console.log('Logging: ', action); + if (action.strategy) { + return strategySuccess(action.strategy); + } else { + return action; + } + }) +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/axium/qualities/open.quality.ts b/src/concepts/axium/qualities/open.quality.ts index 857864e..fd60b24 100644 --- a/src/concepts/axium/qualities/open.quality.ts +++ b/src/concepts/axium/qualities/open.quality.ts @@ -5,28 +5,28 @@ currently in blocking mode. This allows for subscribers to be notified of any ne Or simply that the axium is ready to receive actions. $>*/ /*<#*/ -import { defaultMethodCreator, createQuality } from '../../../model/concept'; -import { Action, ActionType, prepareActionWithPayloadCreator } from '../../../model/action'; +import { defaultMethodCreator } from '../../../model/concept'; import { AxiumState } from '../axium.concept'; import { selectPayload } from '../../../model/selector'; +import { createQualitySetWithPayload } from '../../../model/quality'; export type OpenPayload = { open: boolean }; -export const axiumOpenType: ActionType = 'Open Axium'; -export const axiumOpen = prepareActionWithPayloadCreator(axiumOpenType); - -export function axiumOpenReducer(state: AxiumState, action: Action): AxiumState { - const open = selectPayload(action).open; - return { - ...state, - open, - }; -} -export const axiumOpenQuality = createQuality( +export const [ + axiumOpen, axiumOpenType, - axiumOpenReducer, - defaultMethodCreator -); + axiumOpenQuality +] = createQualitySetWithPayload({ + type: 'Open Axium', + reducer: (state: AxiumState, action) => { + const {open} = selectPayload(action); + return { + ...state, + open + }; + }, + methodCreator: defaultMethodCreator +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/axium/qualities/preClose.quality.ts b/src/concepts/axium/qualities/preClose.quality.ts index cca6966..99e3419 100644 --- a/src/concepts/axium/qualities/preClose.quality.ts +++ b/src/concepts/axium/qualities/preClose.quality.ts @@ -3,10 +3,9 @@ For the asynchronous graph programming framework Stratimux and Axium Concept, ge its close principle that is observing the prepareClose state property. $>*/ /*<#*/ -import { createQuality } from '../../../model/concept'; -import { Action, ActionType, prepareActionWithPayloadCreator } from '../../../model/action'; import { AxiumState } from '../axium.concept'; import { selectPayload } from '../../../model/selector'; +import { createQualitySetWithPayload } from '../../../model/quality'; /** * @parm exit - If set to true, will exit the current process. @@ -14,19 +13,18 @@ import { selectPayload } from '../../../model/selector'; export type AxiumPreClosePayload = { exit: boolean }; -export const axiumPreCloseType: ActionType = 'Prepare Close Axium'; -export const axiumPreClose = prepareActionWithPayloadCreator(axiumPreCloseType); - -export function axiumCloseReducer(state: AxiumState, _action: Action): AxiumState { - return { - ...state, - prepareClose: true, - exit: selectPayload(_action).exit - }; -} - -export const axiumPreCloseQuality = createQuality( +export const [ + axiumPreClose, axiumPreCloseType, - axiumCloseReducer -); + axiumPreCloseQuality +] = createQualitySetWithPayload({ + type: 'Prepare Close Axium', + reducer: (state: AxiumState, action) => { + return { + ...state, + prepareClose: true, + exit: selectPayload(action).exit + }; + } +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/axium/qualities/registerStagePlanner.quality.ts b/src/concepts/axium/qualities/registerStagePlanner.quality.ts index 6e1a8b1..7d07424 100644 --- a/src/concepts/axium/qualities/registerStagePlanner.quality.ts +++ b/src/concepts/axium/qualities/registerStagePlanner.quality.ts @@ -5,35 +5,33 @@ This allows for the closing of hot observables if the concept they are associate $>*/ /*<#*/ import { defaultMethodCreator } from '../../../model/concept'; -import { Action, ActionType, prepareActionWithPayloadCreator } from '../../../model/action'; import { AxiumState } from '../axium.concept'; -import { createQuality } from '../../../model/concept'; import { selectPayload } from '../../../model/selector'; import { StagePlanner } from '../../../model/stagePlanner'; +import { createQualitySetWithPayload } from '../../../model/quality'; export type AxiumRegisterStagePlannerPayload = { stagePlanner: StagePlanner; conceptName: string; } -export const axiumRegisterStagePlannerType: ActionType = 'register Stage Planner to Axium\'s Named Stage Planner list'; -export const axiumRegisterStagePlanner = - prepareActionWithPayloadCreator(axiumRegisterStagePlannerType); -function axiumRegisterSubscriberReducer(state: AxiumState, action: Action): AxiumState { - const payload = selectPayload(action); - const stagePlanners = state.stagePlanners; - const stagePlanner = payload.stagePlanner; - const name = payload.conceptName; - stagePlanners.push({name, ...stagePlanner}); - return { - ...state, - stagePlanners, - }; -} - -export const axiumRegisterStagePlannerQuality = createQuality( +export const [ + axiumRegisterStagePlanner, axiumRegisterStagePlannerType, - axiumRegisterSubscriberReducer, - defaultMethodCreator -); + axiumRegisterStagePlannerQuality +] = createQualitySetWithPayload({ + type: 'register Stage Planner to Axium\'s Named Stage Planner list', + reducer: (state: AxiumState, action) => { + const payload = selectPayload(action); + const stagePlanners = state.stagePlanners; + const stagePlanner = payload.stagePlanner; + const name = payload.conceptName; + stagePlanners.push({name, ...stagePlanner}); + return { + ...state, + stagePlanners, + }; + }, + methodCreator: defaultMethodCreator +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/axium/qualities/registerSubscription.quality.ts b/src/concepts/axium/qualities/registerSubscription.quality.ts index a36bae5..940ec29 100644 --- a/src/concepts/axium/qualities/registerSubscription.quality.ts +++ b/src/concepts/axium/qualities/registerSubscription.quality.ts @@ -6,34 +6,32 @@ $>*/ /*<#*/ import { Subscription } from 'rxjs'; import { defaultMethodCreator } from '../../../model/concept'; -import { Action, ActionType, prepareActionWithPayloadCreator } from '../../../model/action'; import { AxiumState } from '../axium.concept'; -import { createQuality } from '../../../model/concept'; import { selectPayload } from '../../../model/selector'; +import { createQualitySetWithPayload } from '../../../model/quality'; export type AxiumRegisterSubscriberPayload = { subscription: Subscription; name: string; } -export const axiumRegisterSubscriberType: ActionType = 'register Subscriber to Axium\'s General Subscriber list'; -export const axiumRegisterSubscriber = - prepareActionWithPayloadCreator(axiumRegisterSubscriberType); -function axiumRegisterSubscriberReducer(state: AxiumState, action: Action) { - const payload = selectPayload(action); - const generalSubscribers = state.generalSubscribers; - const subscription = payload.subscription; - const name = payload.name; - generalSubscribers.push({name, subscription}); - return { - ...state, - generalSubscribers, - }; -} - -export const axiumRegisterSubscriberQuality = createQuality( +export const [ + axiumRegisterSubscriber, axiumRegisterSubscriberType, - axiumRegisterSubscriberReducer, - defaultMethodCreator -); + axiumRegisterSubscriberQuality +] = createQualitySetWithPayload({ + type: 'register Subscriber to Axium\'s General Subscriber list', + reducer: (state: AxiumState, action) => { + const payload = selectPayload(action); + const generalSubscribers = state.generalSubscribers; + const subscription = payload.subscription; + const name = payload.name; + generalSubscribers.push({name, subscription}); + return { + ...state, + generalSubscribers, + }; + }, + methodCreator: defaultMethodCreator +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/axium/qualities/removeConceptsViaQue.quality.ts b/src/concepts/axium/qualities/removeConceptsViaQue.quality.ts index 8f7c8a1..9310ace 100644 --- a/src/concepts/axium/qualities/removeConceptsViaQue.quality.ts +++ b/src/concepts/axium/qualities/removeConceptsViaQue.quality.ts @@ -6,76 +6,74 @@ $>*/ /*<#*/ import { defaultMethodCreator } from '../../../model/concept'; import { NamedSubscription } from '../axium.concept'; -import { Action, ActionType, prepareActionCreator } from '../../../model/action'; import { AxiumState } from '../axium.concept'; -import { createQuality } from '../../../model/concept'; import { NamedStagePlanner } from '../../../model/stagePlanner'; +import { createQualitySet } from '../../../model/quality'; -export const axiumRemoveConceptsViaQueType: ActionType = 'remove Concepts via Axium\'s Removal Concept Que'; -export const axiumRemoveConceptsViaQue = prepareActionCreator(axiumRemoveConceptsViaQueType); - -function axiumRemoveConceptsViaQueReducer(state: AxiumState, _action: Action) { - const principleSubscribers = state.methodSubscribers; - const newPrincipleSubscribers = [] as NamedSubscription[]; - const generalSubscribers = state.methodSubscribers; - const newGeneralSubscribers = [] as NamedSubscription[]; - const stagePlanners = state.stagePlanners; - const newStagePlanners = [] as NamedStagePlanner[]; - const removeConceptQue = state.removeConceptQue; +export const [ + axiumRemoveConceptsViaQue, + axiumRemoveConceptsViaQueType, + axiumRemoveConceptsViaQueQuality +] = createQualitySet({ + type: 'remove Concepts via Axium\'s Removal Concept Que', + reducer: (state: AxiumState, action) => { + const principleSubscribers = state.methodSubscribers; + const newPrincipleSubscribers = [] as NamedSubscription[]; + const generalSubscribers = state.methodSubscribers; + const newGeneralSubscribers = [] as NamedSubscription[]; + const stagePlanners = state.stagePlanners; + const newStagePlanners = [] as NamedStagePlanner[]; + const removeConceptQue = state.removeConceptQue; - principleSubscribers.forEach(named => { - let exists = false; - removeConceptQue.forEach(concept => { - if (concept.name === named.name) { - exists = true; + principleSubscribers.forEach(named => { + let exists = false; + removeConceptQue.forEach(concept => { + if (concept.name === named.name) { + exists = true; + } + }); + if (!exists) { + newPrincipleSubscribers.push(named); + } else { + named.subscription.unsubscribe(); } }); - if (!exists) { - newPrincipleSubscribers.push(named); - } else { - named.subscription.unsubscribe(); - } - }); - generalSubscribers.forEach(named => { - let exists = false; - removeConceptQue.forEach(concept => { - if (concept.name === named.name) { - exists = true; + generalSubscribers.forEach(named => { + let exists = false; + removeConceptQue.forEach(concept => { + if (concept.name === named.name) { + exists = true; + } + }); + if (!exists) { + newGeneralSubscribers.push(named); + } else { + named.subscription.unsubscribe(); } }); - if (!exists) { - newGeneralSubscribers.push(named); - } else { - named.subscription.unsubscribe(); - } - }); - stagePlanners.forEach(named => { - let exists = false; - removeConceptQue.forEach(concept => { - if (concept.name === named.name) { - exists = true; + stagePlanners.forEach(named => { + let exists = false; + removeConceptQue.forEach(concept => { + if (concept.name === named.name) { + exists = true; + } + }); + if (!exists) { + newStagePlanners.push(named); + } else { + named.conclude(); } }); - if (!exists) { - newStagePlanners.push(named); - } else { - named.conclude(); - } - }); - return { - ...state, - generalSubscribers: newGeneralSubscribers, - stagePlanners: newStagePlanners, - removeConceptQue: [] - }; -} - -export const axiumRemoveConceptsViaQueQuality = createQuality( - axiumRemoveConceptsViaQueType, - axiumRemoveConceptsViaQueReducer, - defaultMethodCreator -); + return { + ...state, + generalSubscribers: newGeneralSubscribers, + stagePlanners: newStagePlanners, + removeConceptQue: [] + }; + }, + methodCreator: defaultMethodCreator +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/axium/qualities/setBlockingMode.quality.ts b/src/concepts/axium/qualities/setBlockingMode.quality.ts index 45afef4..8e87f28 100644 --- a/src/concepts/axium/qualities/setBlockingMode.quality.ts +++ b/src/concepts/axium/qualities/setBlockingMode.quality.ts @@ -6,51 +6,51 @@ $>*/ /*<#*/ import { Subject, Subscriber } from 'rxjs'; import { Concepts, defaultMethodCreator, forEachConcept } from '../../../model/concept'; -import { Action, ActionType, prepareActionWithPayloadCreator } from '../../../model/action'; +import { Action } from '../../../model/action'; import { AxiumState } from '../axium.concept'; -import { createQuality } from '../../../model/concept'; import { blockingMethodSubscription } from '../../../model/axium'; import { selectPayload } from '../../../model/selector'; +import { createQualitySetWithPayload } from '../../../model/quality'; export type AxiumSetBlockingModePayload = { concepts: Concepts } -export const axiumSetBlockingModeType: ActionType = 'set Axium to Blocking Mode'; -export const axiumSetBlockingMode = prepareActionWithPayloadCreator(axiumSetBlockingModeType); -function axiumSetBlockingModeReducer(state: AxiumState, _action: Action): AxiumState { - let methodSubscribers = state.methodSubscribers; - methodSubscribers.forEach(named => named.subscription.unsubscribe()); - methodSubscribers = []; - - const payload = selectPayload(_action); - const concepts = payload.concepts; - forEachConcept(concepts, (concept => { - concept.qualities.forEach(quality => { - if (quality.method) { - const sub = quality.method.subscribe(action => { - const action$ = state.action$ as Subject; - blockingMethodSubscription(action$, action); - }); - methodSubscribers.push({ - name: concept.name, - subscription: sub as Subscriber - }); - } - }); - })); +export const [ + axiumSetBlockingMode, + axiumSetBlockingModeType, + axiumSetBlockingModeQuality +] = createQualitySetWithPayload({ + type: 'set Axium to Blocking Mode', + reducer: (state: AxiumState, _action) => { + let methodSubscribers = state.methodSubscribers; + methodSubscribers.forEach(named => named.subscription.unsubscribe()); + methodSubscribers = []; - return { - ...state, - modeIndex: 0, - methodSubscribers, - open: false, - }; -} + const payload = selectPayload(_action); + const concepts = payload.concepts; + forEachConcept(concepts, (concept => { + concept.qualities.forEach(quality => { + if (quality.method) { + const sub = quality.method.subscribe(action => { + const action$ = state.action$ as Subject; + blockingMethodSubscription(action$, action); + }); + methodSubscribers.push({ + name: concept.name, + subscription: sub as Subscriber + }); + } + }); + })); -export const axiumSetBlockingModeQuality = createQuality( - axiumSetBlockingModeType, - axiumSetBlockingModeReducer, - defaultMethodCreator -); + return { + ...state, + modeIndex: 0, + methodSubscribers, + open: false, + }; + }, + methodCreator: defaultMethodCreator +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/axium/qualities/setDefaultMode.quality.ts b/src/concepts/axium/qualities/setDefaultMode.quality.ts index deb676d..183e0a5 100644 --- a/src/concepts/axium/qualities/setDefaultMode.quality.ts +++ b/src/concepts/axium/qualities/setDefaultMode.quality.ts @@ -5,49 +5,49 @@ $>*/ /*<#*/ import { Subject, Subscriber } from 'rxjs'; import { Concepts, defaultMethodCreator, forEachConcept } from '../../../model/concept'; -import { Action, ActionType, prepareActionWithPayloadCreator } from '../../../model/action'; +import { Action } from '../../../model/action'; import { AxiumState } from '../axium.concept'; -import { createQuality } from '../../../model/concept'; import { defaultMethodSubscription } from '../../../model/axium'; import { selectPayload } from '../../../model/selector'; +import { createQualitySetWithPayload } from '../../../model/quality'; export type AxiumSetDefaultModePayload = { concepts: Concepts } -export const axiumSetDefaultModeType: ActionType = 'set Axium to its current Default Mode Index'; -export const axiumSetDefaultMode = prepareActionWithPayloadCreator(axiumSetDefaultModeType); -function axiumSetDefaultModeReducer(state: AxiumState, _action: Action): AxiumState { - let methodSubscribers = state.methodSubscribers; - methodSubscribers.forEach(named => named.subscription.unsubscribe()); - methodSubscribers = []; - const payload = selectPayload(_action); - const concepts = payload.concepts; - forEachConcept(concepts, (concept => { - concept.qualities.forEach(quality => { - if (quality.method) { - const sub = quality.method.subscribe(action => { - const action$ = state.action$ as Subject; - defaultMethodSubscription(action$, action); - }); - methodSubscribers.push({ - name: concept.name, - subscription: sub as Subscriber - }); - } - }); - })); - - return { - ...state, - modeIndex: state.defaultModeIndex, - methodSubscribers, - }; -} - -export const axiumSetDefaultModeQuality = createQuality( +export const [ + axiumSetDefaultMode, axiumSetDefaultModeType, - axiumSetDefaultModeReducer, - defaultMethodCreator -); + axiumSetDefaultModeQuality +] = createQualitySetWithPayload({ + type: 'set Axium to its current Default Mode Index', + reducer: (state: AxiumState, _action) => { + let methodSubscribers = state.methodSubscribers; + methodSubscribers.forEach(named => named.subscription.unsubscribe()); + methodSubscribers = []; + const payload = selectPayload(_action); + const concepts = payload.concepts; + forEachConcept(concepts, (concept => { + concept.qualities.forEach(quality => { + if (quality.method) { + const sub = quality.method.subscribe(action => { + const action$ = state.action$ as Subject; + defaultMethodSubscription(action$, action); + }); + methodSubscribers.push({ + name: concept.name, + subscription: sub as Subscriber + }); + } + }); + })); + + return { + ...state, + modeIndex: state.defaultModeIndex, + methodSubscribers, + }; + }, + methodCreator: defaultMethodCreator +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/axium/qualities/setDefaultModeIndex.quality.ts b/src/concepts/axium/qualities/setDefaultModeIndex.quality.ts index 9375e41..6258fec 100644 --- a/src/concepts/axium/qualities/setDefaultModeIndex.quality.ts +++ b/src/concepts/axium/qualities/setDefaultModeIndex.quality.ts @@ -4,27 +4,28 @@ generate a quality that will set the default mode index to what is specified by the action's payload. $>*/ /*<#*/ -import { defaultMethodCreator, createQuality } from '../../../model/concept'; -import { Action, ActionType, prepareActionWithPayloadCreator } from '../../../model/action'; +import { defaultMethodCreator } from '../../../model/concept'; import { AxiumState } from '../axium.concept'; import { selectPayload } from '../../../model/selector'; +import { createQualitySetWithPayload } from '../../../model/quality'; export type AxiumSetDefaultModeIndexPayload = { index: number; }; -export const axiumSetDefaultModeIndexType: ActionType = 'set Axium\'s Default Mode Index'; -export const axiumSetDefaultModeIndex = prepareActionWithPayloadCreator(axiumSetDefaultModeIndexType); -export function axiumSetDefaultModeIndexReducer(state: AxiumState, action: Action) { - const payload = selectPayload(action); - return { - ...state, - defaultModeIndex: payload.index, - } as AxiumState; -} -export const axiumSetDefaultModeIndexQuality = createQuality( +export const [ + axiumSetDefaultModeIndex, axiumSetDefaultModeIndexType, - axiumSetDefaultModeIndexReducer, - defaultMethodCreator -); + axiumSetDefaultModeIndexQuality +] = createQualitySetWithPayload({ + type: 'set Axium\'s Default Mode Index', + reducer: (state: AxiumState, action) => { + const payload = selectPayload(action); + return { + ...state, + defaultModeIndex: payload.index, + } as AxiumState; + }, + methodCreator: defaultMethodCreator +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/axium/qualities/setMode.quality.ts b/src/concepts/axium/qualities/setMode.quality.ts index 309cf53..43e8074 100644 --- a/src/concepts/axium/qualities/setMode.quality.ts +++ b/src/concepts/axium/qualities/setMode.quality.ts @@ -3,42 +3,38 @@ For the asynchronous graph programming framework Stratimux and Axium Concept, ge $>*/ /*<#*/ import { AxiumState } from '../axium.concept'; -import { Action, prepareActionWithPayloadCreator} from '../../../model/action'; -import { createQuality, MethodCreator, Method } from '../../../model/concept'; import { strategySuccess } from '../../../model/actionStrategy'; import { selectPayload } from '../../../model/selector'; import { createMethod } from '../../../model/method'; +import { createQualitySetWithPayload } from '../../../model/quality'; export type AxiumSetModePayload = { modeIndex: number; modeName: string; } -export const axiumSetModeType = 'set Axium Mode'; -export const axiumSetMode = prepareActionWithPayloadCreator(axiumSetModeType); - -const axiumSetModeMethodCreator: MethodCreator = () => createMethod((action) => { - const payload = action.payload as AxiumSetModePayload; - if (action.strategy) { - action.strategy.currentNode.successNotes = { - denoter: `to ${payload.modeName}.` +export const [ + axiumSetMode, + axiumSetModeType, + axiumSetModeQuality +] = createQualitySetWithPayload({ + type: 'set Axium Mode', + reducer: (state: AxiumState, action) => { + const payload = selectPayload(action); + return { + ...state, + modeIndex: [payload.modeIndex], }; - return strategySuccess(action.strategy); - } - return action; + }, + methodCreator: () => createMethod((action) => { + const payload = action.payload as AxiumSetModePayload; + if (action.strategy) { + action.strategy.currentNode.successNotes = { + denoter: `to ${payload.modeName}.` + }; + return strategySuccess(action.strategy); + } + return action; + }) }); - -function axiumSetModeReducer(state: AxiumState, _action: Action) { - const payload = selectPayload(_action); - return { - ...state, - modeIndex: [payload.modeIndex], - }; -} - -export const axiumSetModeQuality = createQuality( - axiumSetModeType, - axiumSetModeReducer, - axiumSetModeMethodCreator -); /*#>*/ \ No newline at end of file diff --git a/src/concepts/axium/qualities/stitch.quality.ts b/src/concepts/axium/qualities/stitch.quality.ts index 277aa70..8c9392c 100644 --- a/src/concepts/axium/qualities/stitch.quality.ts +++ b/src/concepts/axium/qualities/stitch.quality.ts @@ -3,34 +3,33 @@ For the asynchronous graph programming framework Stratimux and Axium Concept, generate a quality that will silently start the next step in the strategy graph. $>*/ /*<#*/ -import { prepareActionCreator } from '../../../model/action'; import { strategySuccess } from '../../../model/actionStrategy'; -import { createQuality, defaultReducer } from '../../../model/concept'; -import { ActionType, createMethod } from '../../../model/method'; +import { defaultReducer } from '../../../model/concept'; +import { createMethod } from '../../../model/method'; +import { createQualitySet } from '../../../model/quality'; -export const axiumStitchType: ActionType = 'Axium Stitch'; -export const axiumStitch = prepareActionCreator(axiumStitchType); - -const axiumStitchMethodCreator = () => createMethod((action) => { - if (action.strategy) { - const nextStrategy = strategySuccess(action.strategy); - if (nextStrategy.strategy) { - const actionList = nextStrategy.strategy.actionList; - const newList = []; - for (let i = 0; i < actionList.length - 1; i++) { - newList.push(actionList[i]); +export const [ + axiumStitch, + axiumStitchType, + axiumStitchQuality +] = createQualitySet({ + type: 'Axium Stitch', + reducer: defaultReducer, + methodCreator: () => createMethod((action) => { + if (action.strategy) { + const nextStrategy = strategySuccess(action.strategy); + if (nextStrategy.strategy) { + const actionList = nextStrategy.strategy.actionList; + const newList = []; + for (let i = 0; i < actionList.length - 1; i++) { + newList.push(actionList[i]); + } + nextStrategy.strategy.actionList = newList; } - nextStrategy.strategy.actionList = newList; + return nextStrategy; + } else { + return action; } - return nextStrategy; - } else { - return action; - } + }) }); - -export const axiumStitchQuality = createQuality( - axiumStitchType, - defaultReducer, - axiumStitchMethodCreator -); /*#>*/ \ No newline at end of file diff --git a/src/concepts/chain/qualities/chainEnd.quality.ts b/src/concepts/chain/qualities/chainEnd.quality.ts index f177533..f1af34c 100644 --- a/src/concepts/chain/qualities/chainEnd.quality.ts +++ b/src/concepts/chain/qualities/chainEnd.quality.ts @@ -2,22 +2,21 @@ For the asynchronous graph programming framework Stratimux and Chain Concept, generate a quality will set the chain end property to false $>*/ /*<#*/ -import { Action, ActionType, prepareActionCreator } from '../../../model/action'; -import { createQuality } from '../../../model/concept'; +import { createQualitySet } from '../../../model/quality'; import { ChainState } from '../chain.concept'; -export const chainEndType: ActionType = 'set chain end property to true'; -export const chainEnd = prepareActionCreator(chainEndType); - -function chainPrepareChainReducer(state: ChainState, action: Action) { - return { - ...state, - end: true - }; -} - -export const chainEndQuality = createQuality( +export const [ + chainEnd, chainEndType, - chainPrepareChainReducer, -); + chainEndQuality +] = createQualitySet({ + type: 'set chain end property to true', + reducer: (state: ChainState, action) => { + return { + ...state, + end: true + }; + } +}); + /*#>*/ \ No newline at end of file diff --git a/src/concepts/chain/qualities/prepareChain.quality.ts b/src/concepts/chain/qualities/prepareChain.quality.ts index d98d1cd..bffaa5f 100644 --- a/src/concepts/chain/qualities/prepareChain.quality.ts +++ b/src/concepts/chain/qualities/prepareChain.quality.ts @@ -3,30 +3,30 @@ For the asynchronous graph programming framework Stratimux and Chain Concept, generate a quality will add actions into the Chain's actionQue state property. $>*/ /*<#*/ -import { Action, ActionType, prepareActionWithPayloadCreator } from '../../../model/action'; -import { createQuality } from '../../../model/concept'; +import { Action } from '../../../model/action'; +import { createQualitySetWithPayload } from '../../../model/quality'; import { selectPayload } from '../../../model/selector'; import { ChainState } from '../chain.concept'; -export type ChainDispatchActionsPayload = { +export type ChainPrepareChainPayload = { actions: Action[] } -export const chainDispatchActionsType: ActionType = 'dispatch Actions from Action Que via Payload to be Chained'; -export const chainDispatchActions = prepareActionWithPayloadCreator(chainDispatchActionsType); -function chainPrepareChainReducer(state: ChainState, action: Action) { - const payload = selectPayload(action); - return { - ...state, - actionQue: [ - ...state.actionQue, - ...payload.actions - ] - }; -} - -export const chainPrepareChainQuality = createQuality( - chainDispatchActionsType, - chainPrepareChainReducer, -); +export const [ + chainPrepareChain, + chainPrepareChainType, + chainPrepareChainQuality +] = createQualitySetWithPayload({ + type: 'dispatch Actions from Action Que via Payload to be Chained', + reducer: (state: ChainState, action) => { + const payload = selectPayload(action); + return { + ...state, + actionQue: [ + ...state.actionQue, + ...payload.actions + ] + }; + } +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/counter/qualities/add.quality.ts b/src/concepts/counter/qualities/add.quality.ts index 7049b99..0ebc93c 100644 --- a/src/concepts/counter/qualities/add.quality.ts +++ b/src/concepts/counter/qualities/add.quality.ts @@ -2,26 +2,24 @@ For the asynchronous graph programming framework Stratimux and Counter Concept, generate a quality that will increment the state's count by one. $>*/ /*<#*/ -import { Action, ActionType, prepareActionCreator } from '../../../model/action'; import { defaultMethodCreator } from '../../../model/concept'; import { CounterState } from '../counter.concept'; -import { createQuality } from '../../../model/concept'; import { counterSelectCount } from '../counter.selector'; +import { createQualitySet } from '../../../model/quality'; -export const counterAddType: ActionType = 'Counter Add'; - -export const counterAdd = prepareActionCreator(counterAddType); -function counterAddReducer(state: CounterState, _: Action) { - return { - ...state, - count: state.count + 1 - }; -} - -export const counterAddQuality = createQuality( +export const [ + counterAdd, counterAddType, - counterAddReducer, - defaultMethodCreator, - [counterSelectCount] -); + counterAddQuality +] = createQualitySet({ + type: 'Counter Add', + reducer: (state: CounterState) => { + return { + ...state, + count: state.count + 1 + }; + }, + methodCreator: defaultMethodCreator, + keyedSelectors: [counterSelectCount] +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/counter/qualities/setCount.quality.ts b/src/concepts/counter/qualities/setCount.quality.ts index e5034cf..f3a09c4 100644 --- a/src/concepts/counter/qualities/setCount.quality.ts +++ b/src/concepts/counter/qualities/setCount.quality.ts @@ -5,31 +5,28 @@ by the action's payload. $>*/ /*<#*/ import { defaultMethodCreator } from '../../../model/concept'; -import { Action, prepareActionWithPayloadCreator } from '../../../model/action'; -import { createQuality } from '../../../model/concept'; import { CounterState } from '../counter.concept'; import { counterSelectCount } from '../counter.selector'; import { selectPayload } from '../../../model/selector'; - -export const counterSetCountType = 'Counter set Count'; +import { createQualitySetWithPayload } from '../../../model/quality'; export type CounterSetCountPayload = { newCount: number } -export const counterSetCount = prepareActionWithPayloadCreator(counterSetCountType); - -function counterSetCountReducer(state: CounterState, action: Action) { - const payload = selectPayload(action); - return { - ...state, - count: payload.newCount - }; -} - -export const counterSetCountQuality = createQuality( +export const [ + counterSetCount, counterSetCountType, - counterSetCountReducer, - defaultMethodCreator, - [counterSelectCount] -); + counterSetCountQuality +] = createQualitySetWithPayload({ + type: 'Counter set Count', + reducer: (state: CounterState, action) => { + const {newCount} = selectPayload(action); + return { + ...state, + count: newCount + }; + }, + methodCreator: defaultMethodCreator, + keyedSelectors: [counterSelectCount] +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/counter/qualities/subtract.quality.ts b/src/concepts/counter/qualities/subtract.quality.ts index 3fd6a7f..f7aae11 100644 --- a/src/concepts/counter/qualities/subtract.quality.ts +++ b/src/concepts/counter/qualities/subtract.quality.ts @@ -4,25 +4,22 @@ $>*/ /*<#*/ import { defaultMethodCreator } from '../../../model/concept'; import { CounterState } from '../counter.concept'; -import { ActionType, prepareActionCreator } from '../../../model/action'; -import { createQuality } from '../../../model/concept'; import { counterSelectCount } from '../counter.selector'; +import { createQualitySet } from '../../../model/quality'; -export const counterSubtractType: ActionType = 'Counter Subtract'; - -export const counterSubtract = prepareActionCreator(counterSubtractType); - -function counterSubtractReducer(state: CounterState) { - return { - ...state, - count: state.count - 1 - }; -} - -export const counterSubtractQuality = createQuality( +export const [ + counterSubtract, counterSubtractType, - counterSubtractReducer, - defaultMethodCreator, - [counterSelectCount] -); + counterSubtractQuality +] = createQualitySet({ + type: 'Counter Subtract', + reducer: (state: CounterState, action) => { + return { + ...state, + count: state.count - 1 + }; + }, + methodCreator: defaultMethodCreator, + keyedSelectors: [counterSelectCount] +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/experiment/qualities/asyncIterateIdThenReceiveInMethod.quality.ts b/src/concepts/experiment/qualities/asyncIterateIdThenReceiveInMethod.quality.ts index 510cf34..3877684 100644 --- a/src/concepts/experiment/qualities/asyncIterateIdThenReceiveInMethod.quality.ts +++ b/src/concepts/experiment/qualities/asyncIterateIdThenReceiveInMethod.quality.ts @@ -3,43 +3,37 @@ For the asynchronous graph programming framework Stratimux and Experiment Concep Then its method will asynchronously unify the state's id value onto the strategy. $>*/ /*<#*/ -import { Concepts, MethodCreator } from '../../../model/concept'; -import { Action, prepareActionCreator } from '../../../model/action'; -import { createQuality } from '../../../model/concept'; +import { Concepts } from '../../../model/concept'; import { ExperimentState } from '../experiment.concept'; import { UnifiedSubject } from '../../../model/stagePlanner'; import { createAsyncMethodWithState } from '../../../model/method'; import { strategySuccess } from '../../../model/actionStrategy'; import { strategyData_unifyData } from '../../../model/actionStrategyData'; import { Subject } from 'rxjs'; +import { createQualitySet } from '../../../model/quality'; -export const experimentAsyncIterateIdThenReceiveInMethodType - = 'Experiment asynchronously iterate ID then receive in Method via State'; - -export const experimentAsyncIterateIdThenReceiveInMethod = prepareActionCreator(experimentAsyncIterateIdThenReceiveInMethodType); - -const experimentAsyncIterateIdThenReceiveInMethodCreator: MethodCreator = (concepts$?: Subject, semaphore?: number) => - createAsyncMethodWithState((controller, action, state) => { - setTimeout(() => { - if (action.strategy) { - const data = strategyData_unifyData(action.strategy, {id: state.id}); - const strategy = strategySuccess(action.strategy, data); - controller.fire(strategy); - } - controller.fire(action); - }, 50); - }, concepts$ as UnifiedSubject, semaphore as number); - -function experimentAsyncIterateIdThenReceiveInMethodReducer(state: ExperimentState, _: Action): ExperimentState { - return { - ...state, - id: state.id + 1 - }; -} - -export const experimentAsyncIterateIdThenReceiveInMethodQuality = createQuality( +export const [ + experimentAsyncIterateIdThenReceiveInMethod, experimentAsyncIterateIdThenReceiveInMethodType, - experimentAsyncIterateIdThenReceiveInMethodReducer, - experimentAsyncIterateIdThenReceiveInMethodCreator -); + experimentAsyncIterateIdThenReceiveInMethodQuality +] = createQualitySet({ + type: 'Experiment asynchronously iterate ID then receive in Method via State', + reducer: (state: ExperimentState) => { + return { + ...state, + id: state.id + 1 + }; + }, + methodCreator: (concepts$?: Subject, semaphore?: number) => + createAsyncMethodWithState((controller, action, state) => { + setTimeout(() => { + if (action.strategy) { + const data = strategyData_unifyData(action.strategy, {id: state.id}); + const strategy = strategySuccess(action.strategy, data); + controller.fire(strategy); + } + controller.fire(action); + }, 50); + }, concepts$ as UnifiedSubject, semaphore as number), +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/experiment/qualities/checkInStrategy.quality.ts b/src/concepts/experiment/qualities/checkInStrategy.quality.ts index 45b5601..70e04cd 100644 --- a/src/concepts/experiment/qualities/checkInStrategy.quality.ts +++ b/src/concepts/experiment/qualities/checkInStrategy.quality.ts @@ -3,33 +3,30 @@ For the asynchronous graph programming framework Stratimux and Experiment Concep in the current strategy to the state's actionQue. $>*/ /*<#*/ -import { Action, prepareActionCreator } from '../../../model/action'; -import { createQuality } from '../../../model/concept'; import { strategySuccess } from '../../../model/actionStrategy'; import { axiumConcludeType } from '../../axium/qualities/conclude.quality'; import { ExperimentState } from '../experiment.concept'; +import { createQualitySet } from '../../../model/quality'; -export const experimentCheckInStrategyType = 'Experiment Check in Action'; - -export const experimentCheckInStrategy = prepareActionCreator(experimentCheckInStrategyType); - -function experimentCheckInStrategyReducer(state: ExperimentState, action: Action): ExperimentState { - if (action.strategy) { - const nextAction = strategySuccess(action.strategy); - if (nextAction.type !== axiumConcludeType) { - return { - ...state, - actionQue: [... state.actionQue, nextAction] - }; +export const [ + experimentCheckInStrategy, + experimentCheckInStrategyType, + experimentCheckInStrategyQuality +] = createQualitySet({ + type: 'Experiment check in Action', + reducer: (state: ExperimentState, action) => { + if (action.strategy) { + const nextAction = strategySuccess(action.strategy); + if (nextAction.type !== axiumConcludeType) { + return { + ...state, + actionQue: [... state.actionQue, nextAction] + }; + } } + return { + ...state + }; } - return { - ...state - }; -} - -export const checkInStrategyQuality = createQuality( - experimentCheckInStrategyType, - experimentCheckInStrategyReducer, -); +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/experiment/qualities/debounceAsyncIterateIdThenReceiveInMethod.quality.ts b/src/concepts/experiment/qualities/debounceAsyncIterateIdThenReceiveInMethod.quality.ts index 36f3a24..b257735 100644 --- a/src/concepts/experiment/qualities/debounceAsyncIterateIdThenReceiveInMethod.quality.ts +++ b/src/concepts/experiment/qualities/debounceAsyncIterateIdThenReceiveInMethod.quality.ts @@ -3,9 +3,7 @@ For the asynchronous graph programming framework Stratimux and Experiment Concep Then debounce the action via the qualities method that will then unify the state's id into the strategy's data. $>*/ /*<#*/ -import { Concepts, MethodCreator } from '../../../model/concept'; -import { Action, prepareActionWithPayloadCreator } from '../../../model/action'; -import { createQuality } from '../../../model/concept'; +import { Concepts } from '../../../model/concept'; import { ExperimentState } from '../experiment.concept'; import { UnifiedSubject } from '../../../model/stagePlanner'; import { createAsyncMethodDebounceWithState } from '../../../model/method'; @@ -13,46 +11,41 @@ import { selectPayload } from '../../../model/selector'; import { strategySuccess } from '../../../model/actionStrategy'; import { strategyData_unifyData } from '../../../model/actionStrategyData'; import { Subject } from 'rxjs'; +import { createQualitySetWithPayload } from '../../../model/quality'; export type ExperimentDebounceAsyncIterateIdThenReceiveInMethodPayload = { setId: number; } -export const experimentDebounceAsyncIterateIdThenReceiveInMethodType - = 'Debounce Experiment asynchronously iterate ID then receive in Method via State'; -export const experimentDebounceAsyncIterateIdThenReceiveInMethod - = prepareActionWithPayloadCreator( - experimentDebounceAsyncIterateIdThenReceiveInMethodType - ); -const experimentDebounceAsyncIterateIdThenReceiveInMethodCreator: MethodCreator = (concepts$?: Subject, semaphore?: number) => - createAsyncMethodDebounceWithState((controller, action, state) => { - setTimeout(() => { - const payload = selectPayload(action); - if (action.strategy) { - const data = strategyData_unifyData( - action.strategy, - { - id: state.id, - setId: payload.setId - } - ); - const strategy = strategySuccess(action.strategy, data); - controller.fire(strategy); - } - controller.fire(action); - }, 50); - }, concepts$ as UnifiedSubject, semaphore as number, 500); - -function experimentDebounceAsyncIterateIdThenReceiveInMethodReducer(state: ExperimentState, _: Action): ExperimentState { - return { - ...state, - id: state.id + 1 - }; -} - -export const experimentDebounceAsyncIterateIdThenReceiveInMethodQuality = createQuality( +export const [ + experimentDebounceAsyncIterateIdThenReceiveInMethod, experimentDebounceAsyncIterateIdThenReceiveInMethodType, - experimentDebounceAsyncIterateIdThenReceiveInMethodReducer, - experimentDebounceAsyncIterateIdThenReceiveInMethodCreator -); + experimentDebounceAsyncIterateIdThenReceiveInMethodQuality +] = createQualitySetWithPayload({ + type: 'Debounce Experiment asynchronously iterate ID then receive in Method via State', + reducer: (state: ExperimentState) => { + return { + ...state, + id: state.id + 1 + }; + }, + methodCreator: (concepts$?: Subject, semaphore?: number) => + createAsyncMethodDebounceWithState((controller, action, state) => { + setTimeout(() => { + const payload = selectPayload(action); + if (action.strategy) { + const data = strategyData_unifyData( + action.strategy, + { + id: state.id, + setId: payload.setId + } + ); + const strategy = strategySuccess(action.strategy, data); + controller.fire(strategy); + } + controller.fire(action); + }, 50); + }, concepts$ as UnifiedSubject, semaphore as number, 500) +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/experiment/qualities/debounceAsyncNextActionNode.quality.ts b/src/concepts/experiment/qualities/debounceAsyncNextActionNode.quality.ts index 273ea6d..97f3a1a 100644 --- a/src/concepts/experiment/qualities/debounceAsyncNextActionNode.quality.ts +++ b/src/concepts/experiment/qualities/debounceAsyncNextActionNode.quality.ts @@ -3,28 +3,26 @@ For the asynchronous graph programming framework Stratimux and Experiment Concep in the ongoing strategy. $>*/ /*<#*/ -import { MethodCreator, defaultReducer } from '../../../model/concept'; -import { prepareActionCreator } from '../../../model/action'; -import { createQuality } from '../../../model/concept'; +import { defaultReducer } from '../../../model/concept'; import { createAsyncMethodDebounce } from '../../../model/method'; import { strategySuccess } from '../../../model/actionStrategy'; +import { createQualitySet } from '../../../model/quality'; -export const experimentAsyncDebounceNextActionNodeType = 'Experiment will debounce incoming actions within set duration asynchronously'; -export const experimentAsyncDebounceNextActionNode = prepareActionCreator(experimentAsyncDebounceNextActionNodeType); - -export const experimentDebounceNextActionNodeMethodCreator: MethodCreator = () => createAsyncMethodDebounce((controller, action) => { - setTimeout(() => { - if (action.strategy) { - controller.fire(strategySuccess(action.strategy)); - } else { - controller.fire(action); - } - }, 50); -}, 500); - -export const asyncDebounceNextActionNodeQuality = createQuality( +export const [ + experimentAsyncDebounceNextActionNode, experimentAsyncDebounceNextActionNodeType, - defaultReducer, - experimentDebounceNextActionNodeMethodCreator -); + experimentAsyncDebounceNextActionNodeQuality +] = createQualitySet({ + type: 'Experiment will debounce incoming actions within set duration asynchronously', + reducer: defaultReducer, + methodCreator: () => createAsyncMethodDebounce((controller, action) => { + setTimeout(() => { + if (action.strategy) { + controller.fire(strategySuccess(action.strategy)); + } else { + controller.fire(action); + } + }, 50); + }, 500) +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/experiment/qualities/debounceIterateIdThenReceiveInMethod.quality.ts b/src/concepts/experiment/qualities/debounceIterateIdThenReceiveInMethod.quality.ts index 3b5b34d..9d82679 100644 --- a/src/concepts/experiment/qualities/debounceIterateIdThenReceiveInMethod.quality.ts +++ b/src/concepts/experiment/qualities/debounceIterateIdThenReceiveInMethod.quality.ts @@ -4,9 +4,7 @@ Then debounce the quality of actions within a range. To dispatch the most recent That will finally unify the state id and setId from the payload into the most recent strategies data field. $>*/ /*<#*/ -import { Concepts, MethodCreator } from '../../../model/concept'; -import { Action, prepareActionWithPayloadCreator } from '../../../model/action'; -import { createQuality } from '../../../model/concept'; +import { Concepts } from '../../../model/concept'; import { ExperimentState } from '../experiment.concept'; import { UnifiedSubject } from '../../../model/stagePlanner'; import { createMethodDebounceWithState } from '../../../model/method'; @@ -14,42 +12,36 @@ import { selectPayload } from '../../../model/selector'; import { strategySuccess } from '../../../model/actionStrategy'; import { strategyData_unifyData } from '../../../model/actionStrategyData'; import { Subject } from 'rxjs'; +import { createQualitySetWithPayload } from '../../../model/quality'; export type ExperimentDebounceIterateIdThenReceiveInMethodPayload = { setId: number; } -export const experimentDebounceIterateIdThenReceiveInMethodType = - 'Experiment debounce iterate ID then receive in Method via State'; -export const experimentDebounceIterateIdThenReceiveInMethod = - prepareActionWithPayloadCreator( - experimentDebounceIterateIdThenReceiveInMethodType - ); - -const experimentDebounceIterateIdThenReceiveInMethodCreator: MethodCreator = (concepts$?: Subject, semaphore?: number) => - createMethodDebounceWithState((action, state) => { - const payload = selectPayload(action); - if (action.strategy) { - const data = strategyData_unifyData(action.strategy, { - id: state.id, - setId: payload.setId - }); - const strategy = strategySuccess(action.strategy, data); - return strategy; - } - return action; - }, concepts$ as UnifiedSubject, semaphore as number, 500); - -function experimentDebounceIterateIdThenReceiveInMethodReducer(state: ExperimentState, _: Action): ExperimentState { - return { - ...state, - id: state.id + 1 - }; -} - -export const experimentDebounceIterateIdThenReceiveInMethodQuality = createQuality( +export const [ + experimentDebounceIterateIdThenReceiveInMethod, experimentDebounceIterateIdThenReceiveInMethodType, - experimentDebounceIterateIdThenReceiveInMethodReducer, - experimentDebounceIterateIdThenReceiveInMethodCreator -); + experimentDebounceIterateIdThenReceiveInMethodQuality +] = createQualitySetWithPayload({ + type: 'Experiment debounce iterate ID then receive in Method via State', + reducer: (state: ExperimentState) => { + return { + ...state, + id: state.id + 1 + }; + }, + methodCreator: (concepts$?: Subject, semaphore?: number) => + createMethodDebounceWithState((action, state) => { + const payload = selectPayload(action); + if (action.strategy) { + const data = strategyData_unifyData(action.strategy, { + id: state.id, + setId: payload.setId + }); + const strategy = strategySuccess(action.strategy, data); + return strategy; + } + return action; + }, concepts$ as UnifiedSubject, semaphore as number, 500) +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/experiment/qualities/debounceNextActionNode.quality.ts b/src/concepts/experiment/qualities/debounceNextActionNode.quality.ts index 9521e6f..d767ea9 100644 --- a/src/concepts/experiment/qualities/debounceNextActionNode.quality.ts +++ b/src/concepts/experiment/qualities/debounceNextActionNode.quality.ts @@ -3,26 +3,24 @@ For the asynchronous graph programming framework Stratimux and Experiment Concep recent. Then dispatch the most recent's next action via the supplied action strategy. $>*/ /*<#*/ -import { MethodCreator, defaultReducer, nullReducer } from '../../../model/concept'; -import { prepareActionCreator } from '../../../model/action'; -import { createQuality } from '../../../model/concept'; +import { nullReducer } from '../../../model/concept'; import { createMethodDebounce } from '../../../model/method'; import { strategySuccess } from '../../../model/actionStrategy'; +import { createQualitySet } from '../../../model/quality'; -export const experimentDebounceNextActionNodeType = 'Experiment will debounce incoming actions within set duration'; -export const experimentDebounceNextActionNode = prepareActionCreator(experimentDebounceNextActionNodeType); - -export const experimentDebounceNextActionNodeMethodCreator: MethodCreator = () => createMethodDebounce((action) => { - if (action.strategy) { - return strategySuccess(action.strategy); - } else { - return action; - } -}, 500); - -export const debounceNextActionNodeQuality = createQuality( +export const [ + experimentDebounceNextActionNode, experimentDebounceNextActionNodeType, - nullReducer, - experimentDebounceNextActionNodeMethodCreator -); + experimentDebounceNextActionNodeQuality +] = createQualitySet({ + type: 'Experiment will debounce incoming actions within set duration', + reducer: nullReducer, + methodCreator: () => createMethodDebounce((action) => { + if (action.strategy) { + return strategySuccess(action.strategy); + } else { + return action; + } + }, 500) +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/experiment/qualities/iterateIdThenReceiveInMethod.quality.ts b/src/concepts/experiment/qualities/iterateIdThenReceiveInMethod.quality.ts index 73e5d97..fe669c6 100644 --- a/src/concepts/experiment/qualities/iterateIdThenReceiveInMethod.quality.ts +++ b/src/concepts/experiment/qualities/iterateIdThenReceiveInMethod.quality.ts @@ -3,40 +3,35 @@ For the asynchronous graph programming framework Stratimux and Experiment Concep set the id supplied to the method into the strategy's data field. $>*/ /*<#*/ -import { Concepts, MethodCreator } from '../../../model/concept'; -import { Action, prepareActionCreator } from '../../../model/action'; -import { createQuality } from '../../../model/concept'; +import { Concepts } from '../../../model/concept'; import { ExperimentState } from '../experiment.concept'; import { UnifiedSubject } from '../../../model/stagePlanner'; import { createMethodWithState } from '../../../model/method'; import { strategySuccess } from '../../../model/actionStrategy'; import { strategyData_unifyData } from '../../../model/actionStrategyData'; import { Subject } from 'rxjs'; +import { createQualitySet } from '../../../model/quality'; -export const experimentIterateIdThenReceiveInMethodType = 'Experiment iterate ID then receive in Method via State'; - -export const experimentIterateIdThenReceiveInMethod = prepareActionCreator(experimentIterateIdThenReceiveInMethodType); - -const experimentIterateIdThenReceiveInMethodCreator: MethodCreator = (concepts$?: Subject, semaphore?: number) => - createMethodWithState((action, state) => { - if (action.strategy) { - const data = strategyData_unifyData(action.strategy, {id: state.id}); - const strategy = strategySuccess(action.strategy, data); - return strategy; - } - return action; - }, concepts$ as UnifiedSubject, semaphore as number); - -function experimentIterateIdThenReceiveInMethodReducer(state: ExperimentState, _: Action): ExperimentState { - return { - ...state, - id: state.id + 1 - }; -} - -export const experimentIterateIdThenReceiveInMethodQuality = createQuality( +export const [ + experimentIterateIdThenReceiveInMethod, experimentIterateIdThenReceiveInMethodType, - experimentIterateIdThenReceiveInMethodReducer, - experimentIterateIdThenReceiveInMethodCreator -); + experimentIterateIdThenReceiveInMethodQuality +] = createQualitySet({ + type: 'Experiment iterate ID then receive in Method via State', + reducer: (state: ExperimentState) => { + return { + ...state, + id: state.id + 1 + }; + }, + methodCreator: (concepts$?: Subject, semaphore?: number) => + createMethodWithState((action, state) => { + if (action.strategy) { + const data = strategyData_unifyData(action.strategy, {id: state.id}); + const strategy = strategySuccess(action.strategy, data); + return strategy; + } + return action; + }, concepts$ as UnifiedSubject, semaphore as number) +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/experiment/qualities/mockToTrue.quality.ts b/src/concepts/experiment/qualities/mockToTrue.quality.ts new file mode 100644 index 0000000..48c22fa --- /dev/null +++ b/src/concepts/experiment/qualities/mockToTrue.quality.ts @@ -0,0 +1,23 @@ +/*<$ +For the asynchronous graph programming framework Stratimux and Experiment Concept, generate a quality that will set mock to true. +$>*/ +/*<#*/ +import { defaultMethodCreator } from '../../../model/concept'; +import { ExperimentState } from '../experiment.concept'; +import { createQualitySet } from '../../../model/quality'; + +export const [ + experimentMockToTrue, + experimentMockToTrueType, + experimentMockToTrueQuality, +] = createQualitySet({ + type: 'Experiment mock set to True', + reducer: (state: ExperimentState) => { + return { + ...state, + mock: true + }; + }, + methodCreator: defaultMethodCreator +}); +/*#>*/ \ No newline at end of file diff --git a/src/concepts/experiment/qualities/mockTrue.quality.ts b/src/concepts/experiment/qualities/mockTrue.quality.ts deleted file mode 100644 index 36e4b99..0000000 --- a/src/concepts/experiment/qualities/mockTrue.quality.ts +++ /dev/null @@ -1,26 +0,0 @@ -/*<$ -For the asynchronous graph programming framework Stratimux and Experiment Concept, generate a quality that will set mock to true. -$>*/ -/*<#*/ -import { defaultMethodCreator } from '../../../model/concept'; -import { Action, prepareActionCreator } from '../../../model/action'; -import { createQuality } from '../../../model/concept'; -import { ExperimentState } from '../experiment.concept'; - -export const experimentMockTrueType = 'Experiment mock set to True'; - -export const experimentMockTrue = prepareActionCreator(experimentMockTrueType); - -export function checkInStrategyReducer(state: ExperimentState, action: Action): ExperimentState { - return { - ...state, - mock: true - }; -} - -export const mockToTrueQuality = createQuality( - experimentMockTrueType, - checkInStrategyReducer, - defaultMethodCreator -); -/*#>*/ \ No newline at end of file diff --git a/src/concepts/experiment/qualities/recurseIncrementId.quality.ts b/src/concepts/experiment/qualities/recurseIncrementId.quality.ts index 600d4e9..a67604e 100644 --- a/src/concepts/experiment/qualities/recurseIncrementId.quality.ts +++ b/src/concepts/experiment/qualities/recurseIncrementId.quality.ts @@ -3,9 +3,7 @@ For the asynchronous graph programming framework Stratimux and Experiment Concep limited via a control variable that is an arbitrary string array that is shifted until depleted. $>*/ /*<#*/ -import { Concepts, MethodCreator } from '../../../model/concept'; -import { Action, prepareActionWithPayloadCreator } from '../../../model/action'; -import { createQuality } from '../../../model/concept'; +import { Concepts } from '../../../model/concept'; import { ExperimentState } from '../experiment.concept'; import { UnifiedSubject } from '../../../model/stagePlanner'; import { createAsyncMethodWithState } from '../../../model/method'; @@ -13,42 +11,41 @@ import { selectPayload } from '../../../model/selector'; import { strategyRecurse, strategySuccess } from '../../../model/actionStrategy'; import { strategyData_unifyData } from '../../../model/actionStrategyData'; import { Subject } from 'rxjs'; +import { createQualitySetWithPayload } from '../../../model/quality'; -export type ExperimentRecurseIterateId = {controlling: string[]}; -export const experimentRecurseIterateIdType - = 'Asynchronous experiment, recursively iterate ID and receive in Method via State'; +export type ExperimentRecurseIterateId = { + controlling: string[] +}; -export const experimentRecurseIterateId = prepareActionWithPayloadCreator(experimentRecurseIterateIdType); - -const experimentRecurseIterateIdCreator: MethodCreator = (concepts$?: Subject, semaphore?: number) => - createAsyncMethodWithState((controller, action, state) => { - setTimeout(() => { - const payload = selectPayload(action); - payload.controlling.shift(); - if (action.strategy) { - const data = strategyData_unifyData(action.strategy, {id: state.id}); - if (payload.controlling.length > 0) { - const strategy = strategyRecurse(action.strategy, {payload}); - controller.fire(strategy); - } else { - const strategy = strategySuccess(action.strategy, data); - controller.fire(strategy); - } - } - controller.fire(action); - }, 50); - }, concepts$ as UnifiedSubject, semaphore as number); - -function experimentRecurseIterateIdReducer(state: ExperimentState, _: Action): ExperimentState { - return { - ...state, - id: state.id + 1 - }; -} - -export const experimentRecurseIterateIdQuality = createQuality( +export const [ + experimentRecurseIterateId, experimentRecurseIterateIdType, - experimentRecurseIterateIdReducer, - experimentRecurseIterateIdCreator -); + experimentRecurseIterateIdQuality +] = createQualitySetWithPayload({ + type: 'Asynchronous experiment, recursively iterate ID and receive in Method via State', + reducer: (state: ExperimentState) => { + return { + ...state, + id: state.id + 1 + }; + }, + methodCreator: (concepts$?: Subject, semaphore?: number) => + createAsyncMethodWithState((controller, action, state) => { + setTimeout(() => { + const payload = selectPayload(action); + payload.controlling.shift(); + if (action.strategy) { + const data = strategyData_unifyData(action.strategy, {id: state.id}); + if (payload.controlling.length > 0) { + const strategy = strategyRecurse(action.strategy, {payload}); + controller.fire(strategy); + } else { + const strategy = strategySuccess(action.strategy, data); + controller.fire(strategy); + } + } + controller.fire(action); + }, 50); + }, concepts$ as UnifiedSubject, semaphore as number) +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/experiment/qualities/throttleAsyncIterateIdThenReceiveInMethod.quality.ts b/src/concepts/experiment/qualities/throttleAsyncIterateIdThenReceiveInMethod.quality.ts index 38a2fd7..66f67fa 100644 --- a/src/concepts/experiment/qualities/throttleAsyncIterateIdThenReceiveInMethod.quality.ts +++ b/src/concepts/experiment/qualities/throttleAsyncIterateIdThenReceiveInMethod.quality.ts @@ -3,9 +3,7 @@ For the asynchronous graph programming framework Stratimux and Experiment Concep asynchronously dispatch the next action in the incoming strategy, then throttle the quality for a period of time. $>*/ /*<#*/ -import { Concepts, MethodCreator } from '../../../model/concept'; -import { Action, prepareActionWithPayloadCreator } from '../../../model/action'; -import { createQuality } from '../../../model/concept'; +import { Concepts } from '../../../model/concept'; import { ExperimentState } from '../experiment.concept'; import { UnifiedSubject } from '../../../model/stagePlanner'; import { createAsyncMethodThrottleWithState } from '../../../model/method'; @@ -13,46 +11,41 @@ import { selectPayload } from '../../../model/selector'; import { strategySuccess } from '../../../model/actionStrategy'; import { strategyData_unifyData } from '../../../model/actionStrategyData'; import { Subject } from 'rxjs'; +import { createQualitySetWithPayload } from '../../../model/quality'; export type ExperimentThrottleAsyncIterateIdThenReceiveInMethodPayload = { setId: number; } -export const experimentThrottleAsyncIterateIdThenReceiveInMethodType - = 'Action Debounce Experiment asynchronously iterate ID then receive in Method via State'; -export const experimentThrottleAsyncIterateIdThenReceiveInMethod - = prepareActionWithPayloadCreator( - experimentThrottleAsyncIterateIdThenReceiveInMethodType - ); -const experimentThrottleAsyncIterateIdThenReceiveInMethodCreator: MethodCreator = (concepts$?: Subject, semaphore?: number) => - createAsyncMethodThrottleWithState((controller, action, state) => { - setTimeout(() => { - const payload = selectPayload(action); - if (action.strategy) { - const data = strategyData_unifyData( - action.strategy, - { - id: state.id, - setId: payload.setId - } - ); - const strategy = strategySuccess(action.strategy, data); - controller.fire(strategy); - } - controller.fire(action); - }, 50); - }, concepts$ as UnifiedSubject, semaphore as number, 500); - -function experimentThrottleAsyncIterateIdThenReceiveInMethodReducer(state: ExperimentState, _: Action): ExperimentState { - return { - ...state, - id: state.id + 1 - }; -} - -export const experimentThrottleAsyncIterateIdThenReceiveInMethodQuality = createQuality( +export const [ + experimentThrottleAsyncIterateIdThenReceiveInMethod, experimentThrottleAsyncIterateIdThenReceiveInMethodType, - experimentThrottleAsyncIterateIdThenReceiveInMethodReducer, - experimentThrottleAsyncIterateIdThenReceiveInMethodCreator -); + experimentThrottleAsyncIterateIdThenReceiveInMethodQuality +] = createQualitySetWithPayload({ + type: 'Action Debounce Experiment asynchronously iterate ID then receive in Method via State', + reducer: (state: ExperimentState) => { + return { + ...state, + id: state.id + 1 + }; + }, + methodCreator: (concepts$?: Subject, semaphore?: number) => + createAsyncMethodThrottleWithState((controller, action, state) => { + setTimeout(() => { + const payload = selectPayload(action); + if (action.strategy) { + const data = strategyData_unifyData( + action.strategy, + { + id: state.id, + setId: payload.setId + } + ); + const strategy = strategySuccess(action.strategy, data); + controller.fire(strategy); + } + controller.fire(action); + }, 50); + }, concepts$ as UnifiedSubject, semaphore as number, 500) +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/experiment/qualities/throttleIterateIdThenReceiveInMethod.quality.ts b/src/concepts/experiment/qualities/throttleIterateIdThenReceiveInMethod.quality.ts index 7de649b..d05e731 100644 --- a/src/concepts/experiment/qualities/throttleIterateIdThenReceiveInMethod.quality.ts +++ b/src/concepts/experiment/qualities/throttleIterateIdThenReceiveInMethod.quality.ts @@ -3,9 +3,7 @@ For the asynchronous graph programming framework Stratimux and Experiment Concep dispatch the next action in the incoming strategy, then throttle the quality for a period of time. $>*/ /*<#*/ -import { Concepts, MethodCreator } from '../../../model/concept'; -import { Action, prepareActionWithPayloadCreator } from '../../../model/action'; -import { createQuality } from '../../../model/concept'; +import { Concepts } from '../../../model/concept'; import { ExperimentState } from '../experiment.concept'; import { UnifiedSubject } from '../../../model/stagePlanner'; import { createMethodThrottleWithState } from '../../../model/method'; @@ -13,42 +11,36 @@ import { selectPayload } from '../../../model/selector'; import { strategySuccess } from '../../../model/actionStrategy'; import { strategyData_unifyData } from '../../../model/actionStrategyData'; import { Subject } from 'rxjs'; +import { createQualitySetWithPayload } from '../../../model/quality'; export type ExperimentThrottleIterateIdThenReceiveInMethodPayload = { setId: number; } -export const experimentThrottleIterateIdThenReceiveInMethodType = - 'Experiment throttle iterate ID then receive in Method via State'; -export const experimentThrottleIterateIdThenReceiveInMethod = - prepareActionWithPayloadCreator( - experimentThrottleIterateIdThenReceiveInMethodType - ); - -const experimentThrottleIterateIdThenReceiveInMethodCreator: MethodCreator = (concepts$?: Subject, semaphore?: number) => - createMethodThrottleWithState((action, state) => { - const payload = selectPayload(action); - if (action.strategy) { - const data = strategyData_unifyData(action.strategy, { - id: state.id, - setId: payload.setId - }); - const strategy = strategySuccess(action.strategy, data); - return strategy; - } - return action; - }, concepts$ as UnifiedSubject, semaphore as number, 500); - -function experimentThrottleIterateIdThenReceiveInMethodReducer(state: ExperimentState, _: Action): ExperimentState { - return { - ...state, - id: state.id + 1 - }; -} - -export const experimentThrottleIterateIdThenReceiveInMethodQuality = createQuality( +export const [ + experimentThrottleIterateIdThenReceiveInMethod, experimentThrottleIterateIdThenReceiveInMethodType, - experimentThrottleIterateIdThenReceiveInMethodReducer, - experimentThrottleIterateIdThenReceiveInMethodCreator -); + experimentThrottleIterateIdThenReceiveInMethodQuality +] = createQualitySetWithPayload({ + type: 'Experiment throttle iterate ID then receive in Method via State', + reducer: (state: ExperimentState) => { + return { + ...state, + id: state.id + 1 + }; + }, + methodCreator: (concepts$?: Subject, semaphore?: number) => + createMethodThrottleWithState((action, state) => { + const payload = selectPayload(action); + if (action.strategy) { + const data = strategyData_unifyData(action.strategy, { + id: state.id, + setId: payload.setId + }); + const strategy = strategySuccess(action.strategy, data); + return strategy; + } + return action; + }, concepts$ as UnifiedSubject, semaphore as number, 500) +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/experiment/qualities/timerEmitAction.quality.ts b/src/concepts/experiment/qualities/timerEmitAction.quality.ts index d4b7136..e143681 100644 --- a/src/concepts/experiment/qualities/timerEmitAction.quality.ts +++ b/src/concepts/experiment/qualities/timerEmitAction.quality.ts @@ -3,29 +3,27 @@ For the asynchronous graph programming framework Stratimux and Experiment Concep action in the incoming strategy via an inner timer. $>*/ /*<#*/ -import { MethodCreator, defaultReducer, nullReducer } from '../../../model/concept'; -import { prepareActionCreator } from '../../../model/action'; -import { createQuality } from '../../../model/concept'; +import { nullReducer } from '../../../model/concept'; import { createAsyncMethod } from '../../../model/method'; import { strategySuccess } from '../../../model/actionStrategy'; import { axiumConclude } from '../../axium/qualities/conclude.quality'; +import { createQualitySet } from '../../../model/quality'; -export const experimentTimerEmitActionType = 'Experiment create async method with timer, to return action'; -export const experimentTimerEmitAction = prepareActionCreator(experimentTimerEmitActionType); - -export const experimentTimerEmitActionMethodCreator: MethodCreator = () => createAsyncMethod((controller, action) => { - setTimeout(() => { - if (action.strategy) { - controller.fire(strategySuccess(action.strategy)); - } else { - controller.fire(axiumConclude()); - } - }, 50); -}); - -export const timerEmitActionQuality = createQuality( +export const [ + experimentTimerEmitAction, experimentTimerEmitActionType, - nullReducer, - experimentTimerEmitActionMethodCreator -); + experimentTimerEmitActionQuality +] = createQualitySet({ + type: 'Experiment create async method with timer, to return action', + reducer: nullReducer, + methodCreator: () => createAsyncMethod((controller, action) => { + setTimeout(() => { + if (action.strategy) { + controller.fire(strategySuccess(action.strategy)); + } else { + controller.fire(axiumConclude()); + } + }, 50); + }) +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/experiment/qualities/timerEmitActionWithState.quality.ts b/src/concepts/experiment/qualities/timerEmitActionWithState.quality.ts index 6a3533f..b01813e 100644 --- a/src/concepts/experiment/qualities/timerEmitActionWithState.quality.ts +++ b/src/concepts/experiment/qualities/timerEmitActionWithState.quality.ts @@ -3,9 +3,7 @@ For the asynchronous graph programming framework Stratimux and Experiment Concep next action in the ActionStrategy via a timeout. While appending to the strategy's data field the current mock value from state. $>*/ /*<#*/ -import { Concepts, MethodCreator, defaultReducer, nullReducer } from '../../../model/concept'; -import { prepareActionCreator } from '../../../model/action'; -import { createQuality } from '../../../model/concept'; +import { Concepts, nullReducer } from '../../../model/concept'; import { createAsyncMethodWithState } from '../../../model/method'; import { strategySuccess } from '../../../model/actionStrategy'; import { axiumConclude } from '../../axium/qualities/conclude.quality'; @@ -13,25 +11,25 @@ import { UnifiedSubject } from '../../../model/stagePlanner'; import { strategyData_unifyData } from '../../../model/actionStrategyData'; import { ExperimentState } from '../experiment.concept'; import { Subject } from 'rxjs'; +import { createQualitySet } from '../../../model/quality'; -export const experimentTimerEmitActionWithStateType = 'Experiment create async method with timer and state, to return action'; -export const experimentTimerEmitActionWithState = prepareActionCreator(experimentTimerEmitActionWithStateType); - -export const experimentTimerEmitActionWithStateMethodCreator: MethodCreator = (concepts$?: Subject, semaphore?: number) => - createAsyncMethodWithState((controller, action, state) => { - setTimeout(() => { - if (action.strategy) { - const data = strategyData_unifyData(action.strategy, { mock: state.mock }); - controller.fire(strategySuccess(action.strategy, data)); - } else { - controller.fire(axiumConclude()); - } - }, 50); - }, concepts$ as UnifiedSubject, semaphore as number); - -export const timerEmitActionWithStateQuality = createQuality( +export const [ + experimentTimerEmitActionWithState, experimentTimerEmitActionWithStateType, - nullReducer, - experimentTimerEmitActionWithStateMethodCreator -); + experimentTimerEmitActionWithStateQuality +] = createQualitySet({ + type: 'Experiment create async method with timer and state, to return action', + reducer: nullReducer, + methodCreator: (concepts$?: Subject, semaphore?: number) => + createAsyncMethodWithState((controller, action, state) => { + setTimeout(() => { + if (action.strategy) { + const data = strategyData_unifyData(action.strategy, { mock: state.mock }); + controller.fire(strategySuccess(action.strategy, data)); + } else { + controller.fire(axiumConclude()); + } + }, 50); + }, concepts$ as UnifiedSubject, semaphore as number) +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/experiment/strategies/timedMockToTrue.strategy.ts b/src/concepts/experiment/strategies/timedMockToTrue.strategy.ts index c556c2f..7cc1707 100644 --- a/src/concepts/experiment/strategies/timedMockToTrue.strategy.ts +++ b/src/concepts/experiment/strategies/timedMockToTrue.strategy.ts @@ -5,12 +5,12 @@ to true. This is accomplished via a timer emit action quality. That will then fi $>*/ /*<#*/ import { ActionStrategy, ActionStrategyParameters, createActionNode, createStrategy } from '../../../model/actionStrategy'; -import { experimentMockTrue } from '../qualities/mockTrue.quality'; +import { experimentMockToTrue } from '../qualities/mockToTrue.quality'; import { experimentTimerEmitAction } from '../qualities/timerEmitAction.quality'; export const experimentTimedMockToTrueTopic = 'This will use a async method to eventually set mock to True'; export function experimentTimedMockToTrue(): ActionStrategy { - const stepTwo = createActionNode(experimentMockTrue(), { + const stepTwo = createActionNode(experimentMockToTrue(), { successNode: null, failureNode: null, }); diff --git a/src/concepts/experiment/strategies/timedMockToTrueWithState.strategy.ts b/src/concepts/experiment/strategies/timedMockToTrueWithState.strategy.ts index d52b9c7..3703fd2 100644 --- a/src/concepts/experiment/strategies/timedMockToTrueWithState.strategy.ts +++ b/src/concepts/experiment/strategies/timedMockToTrueWithState.strategy.ts @@ -6,13 +6,13 @@ step that will finally set the value to true. Then notify the axium of the strat $>*/ /*<#*/ import { ActionStrategy, ActionStrategyParameters, createActionNode, createStrategy } from '../../../model/actionStrategy'; -import { experimentMockTrue } from '../qualities/mockTrue.quality'; +import { experimentMockToTrue } from '../qualities/mockToTrue.quality'; import { experimentTimerEmitActionWithState } from '../qualities/timerEmitActionWithState.quality'; export const experimentTimedMockToTrueWithStateTopic = 'This will use a async method to eventually set mock to True via State and append mock to strategy data.'; export function timedMockToTrueWithState(): ActionStrategy { - const stepTwo = createActionNode(experimentMockTrue(), { + const stepTwo = createActionNode(experimentMockToTrue(), { successNode: null, failureNode: null, }); diff --git a/src/concepts/ownership/ownership.concept.ts b/src/concepts/ownership/ownership.concept.ts index 6c87f0a..5c0d386 100644 --- a/src/concepts/ownership/ownership.concept.ts +++ b/src/concepts/ownership/ownership.concept.ts @@ -8,15 +8,15 @@ $>*/ import { createConcept } from '../../model/concept'; import { Action } from '../../model/action'; import { ownershipMode } from './ownership.mode'; -import { initializeOwnershipQuality } from './qualities/initializeOwnership.quality'; +import { ownershipInitializeOwnershipQuality } from './qualities/initializeOwnership.quality'; import { ownershipExpirationPrinciple, ownershipPrinciple } from './ownership.principle'; import { OwnershipLedger, createOwnershipLedger } from '../../model/ownership'; -import { backTrackQuality } from './qualities/backTrack.quality'; -import { clearPayloadStubsQuality } from './qualities/clearPayloadStubs.quality'; -import { clearStrategyStubsFromLedgerAndSelfQuality } from './qualities/clearStrategyStubsFromLedgerAndSelf.quality'; -import { clearPendingActionsQuality } from './qualities/clearPendingActions.quality'; -import { clearPendingActionsOfStrategyQuality } from './qualities/clearPendingActionsOfStrategy.quality'; -import { resetOwnershipLedgerQuality } from './qualities/resetOwnershipLedger.quality'; +import { ownershipBackTrackQuality } from './qualities/backTrack.quality'; +import { ownershipClearPayloadStubsQuality } from './qualities/clearPayloadStubs.quality'; +import { ownershipClearStrategyStubsFromLedgerAndSelfQuality } from './qualities/clearStrategyStubsFromLedgerAndSelf.quality'; +import { ownershipClearPendingActionsQuality } from './qualities/clearPendingActions.quality'; +import { ownershipClearPendingActionsOfStrategyQuality } from './qualities/clearPendingActionsOfStrategy.quality'; +import { ownershipResetOwnershipLedgerQuality } from './qualities/resetOwnershipLedger.quality'; export type OwnershipState = { initialized: boolean; @@ -43,13 +43,13 @@ export const createOwnershipConcept = (isResponsibleForMode?: boolean) => { ownershipName, createOwnershipState(isResponsibleForMode ? isResponsibleForMode : true), [ - initializeOwnershipQuality, - backTrackQuality, - clearPayloadStubsQuality, - clearStrategyStubsFromLedgerAndSelfQuality, - clearPendingActionsQuality, - clearPendingActionsOfStrategyQuality, - resetOwnershipLedgerQuality + ownershipInitializeOwnershipQuality, + ownershipBackTrackQuality, + ownershipClearPayloadStubsQuality, + ownershipClearStrategyStubsFromLedgerAndSelfQuality, + ownershipClearPendingActionsQuality, + ownershipClearPendingActionsOfStrategyQuality, + ownershipResetOwnershipLedgerQuality ], [ ownershipPrinciple, diff --git a/src/concepts/ownership/qualities/backTrack.quality.ts b/src/concepts/ownership/qualities/backTrack.quality.ts index 03a13f7..67dcb99 100644 --- a/src/concepts/ownership/qualities/backTrack.quality.ts +++ b/src/concepts/ownership/qualities/backTrack.quality.ts @@ -2,26 +2,25 @@ For the asynchronous graph programming framework Stratimux and Ownership Concept, generate a quality that will back track the provided strategy. $>*/ /*<#*/ -import { MethodCreator, createQuality, defaultReducer, nullReducer } from '../../../model/concept'; -import { ActionType, prepareActionCreator } from '../../../model/action'; +import { nullReducer } from '../../../model/concept'; import { strategyBackTrack } from '../../../model/actionStrategy'; import { createMethod } from '../../../model/method'; +import { createQualitySet } from '../../../model/quality'; -export const ownershipBackTrackType: ActionType = 'backtracking to previous ActionNode'; -export const ownershipBackTrack = prepareActionCreator(ownershipBackTrackType); - -const ownershipCreateBackTrackMethodCreator: MethodCreator = () => createMethod((action) => { - if (action.strategy) { - const newAction = strategyBackTrack(action.strategy); - return newAction; - } else { - return action; - } -}); - -export const backTrackQuality = createQuality( +export const [ + ownershipBackTrack, ownershipBackTrackType, - nullReducer, - ownershipCreateBackTrackMethodCreator, -); + ownershipBackTrackQuality +] = createQualitySet({ + type: 'backtracking to previous ActionNode', + reducer: nullReducer, + methodCreator: () => createMethod((action) => { + if (action.strategy) { + const newAction = strategyBackTrack(action.strategy); + return newAction; + } else { + return action; + } + }) +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/ownership/qualities/clearPayloadStubs.quality.ts b/src/concepts/ownership/qualities/clearPayloadStubs.quality.ts index 2ae3295..95ef432 100644 --- a/src/concepts/ownership/qualities/clearPayloadStubs.quality.ts +++ b/src/concepts/ownership/qualities/clearPayloadStubs.quality.ts @@ -4,46 +4,46 @@ generate a quality that will clear the provided stubs from the current Ownership If no tickets exist within a line, delete that line from the ledger. $>*/ /*<#*/ -import { createQuality, defaultMethodCreator } from '../../../model/concept'; -import { Action, ActionType, prepareActionWithPayloadCreator } from '../../../model/action'; +import { defaultMethodCreator } from '../../../model/concept'; import { OwnershipState } from '../ownership.concept'; import { OwnershipTicket, OwnershipTicketStub } from '../../../model/ownership'; import { selectPayload } from '../../../model/selector'; +import { createQualitySetWithPayload } from '../../../model/quality'; export type OwnershipClearPayloadStubsPayload = { stubs: OwnershipTicketStub[] }; -export const ownershipClearPayloadStubsType: ActionType = 'clear payload Stubs from Ownership Ledger'; -export const ownershipClearPayloadStubs = - prepareActionWithPayloadCreator(ownershipClearPayloadStubsType); -function ownershipClearPayloadStubsReducer(state: OwnershipState, action: Action): OwnershipState { - const stubs = selectPayload(action).stubs; - const ownershipLedger = state.ownershipLedger; - stubs.forEach(ticketStub => { - const line = ownershipLedger.get(ticketStub.key); - if (line) { - const newLine = [] as OwnershipTicket[]; - for (const stub of line) { - if (stub.ticket !== ticketStub.ticket) { - newLine.push(stub); +export const [ + ownershipClearPayloadStubs, + ownershipClearPayloadStubsType, + ownershipClearPayloadStubsQuality +] = createQualitySetWithPayload({ + type: 'clear payload Stubs from Ownership Ledger', + reducer: (state: OwnershipState, action) => { + const stubs = selectPayload(action).stubs; + const ownershipLedger = state.ownershipLedger; + stubs.forEach(ticketStub => { + const line = ownershipLedger.get(ticketStub.key); + if (line) { + const newLine = [] as OwnershipTicket[]; + for (const stub of line) { + if (stub.ticket !== ticketStub.ticket) { + newLine.push(stub); + } + } + if (newLine.length === 0) { + ownershipLedger.delete(ticketStub.key); + } else { + ownershipLedger.set(ticketStub.key, newLine); } } - if (newLine.length === 0) { - ownershipLedger.delete(ticketStub.key); - } else { - ownershipLedger.set(ticketStub.key, newLine); - } - } - }); - return { - ...state, - ownershipLedger: ownershipLedger - }; -} -export const clearPayloadStubsQuality = createQuality( - ownershipClearPayloadStubsType, - ownershipClearPayloadStubsReducer, - defaultMethodCreator -); + }); + return { + ...state, + ownershipLedger: ownershipLedger + }; + }, + methodCreator: defaultMethodCreator +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/ownership/qualities/clearPendingActions.quality.ts b/src/concepts/ownership/qualities/clearPendingActions.quality.ts index 46086bf..6f6faa7 100644 --- a/src/concepts/ownership/qualities/clearPendingActions.quality.ts +++ b/src/concepts/ownership/qualities/clearPendingActions.quality.ts @@ -3,22 +3,17 @@ For the asynchronous graph programming framework Stratimux and Ownership Concept generate a quality that will clear the current pending actions list on state. $>*/ /*<#*/ -import { createQuality, defaultMethodCreator } from '../../../model/concept'; -import { Action, ActionType, prepareActionCreator } from '../../../model/action'; +import { defaultMethodCreator } from '../../../model/concept'; import { OwnershipState } from '../ownership.concept'; +import { createQualitySet } from '../../../model/quality'; -export const ownershipClearPendingActionsType: ActionType = 'clear Ownership\'s Pending Actions'; -export const ownershipClearPendingActions = prepareActionCreator(ownershipClearPendingActionsType); - -function ownershipClearPendingActionsReducer(state: OwnershipState, _: Action): OwnershipState { - return { - ...state, - pendingActions: [] - }; -} -export const clearPendingActionsQuality = createQuality( +export const [ + ownershipClearPendingActions, ownershipClearPendingActionsType, - ownershipClearPendingActionsReducer, - defaultMethodCreator -); + ownershipClearPendingActionsQuality +] = createQualitySet({ + type: 'clear Ownership\'s Pending Actions', + reducer: (state: OwnershipState): OwnershipState => ({...state, pendingActions: []}), + methodCreator: defaultMethodCreator +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/ownership/qualities/clearPendingActionsOfStrategy.quality.ts b/src/concepts/ownership/qualities/clearPendingActionsOfStrategy.quality.ts index d385901..d82c65a 100644 --- a/src/concepts/ownership/qualities/clearPendingActionsOfStrategy.quality.ts +++ b/src/concepts/ownership/qualities/clearPendingActionsOfStrategy.quality.ts @@ -3,37 +3,36 @@ For the asynchronous graph programming framework Stratimux and Ownership Concept generate a quality clear pending actions of the provided ActionStrategy topic. $>*/ /*<#*/ -import { createQuality, defaultMethodCreator } from '../../../model/concept'; -import { Action, ActionType, prepareActionWithPayloadCreator } from '../../../model/action'; +import { Action } from '../../../model/action'; import { OwnershipState } from '../ownership.concept'; import { ActionStrategyTopic } from '../../../model/actionStrategy'; import { selectPayload } from '../../../model/selector'; +import { createQualitySetWithPayload } from '../../../model/quality'; export type OwnershipClearPendingActionsOfStrategyPayload = { topic: ActionStrategyTopic }; -export const ownershipClearPendingActionsOfStrategyType: ActionType = 'clear Ownership\'s Pending Actions of Strategy Topic'; -export const ownershipClearPendingActionsOfStrategy = - prepareActionWithPayloadCreator(ownershipClearPendingActionsOfStrategyType); -function ownershipClearPendingActionsOfStrategyReducer(state: OwnershipState, action: Action): OwnershipState { - const topic = selectPayload(action).topic; - const newPendingActions: Action[] = []; - for (const act of state.pendingActions) { - if (act.strategy?.topic) { - if (act.strategy.topic !== topic) { - newPendingActions.push(act); +export const [ + ownershipClearPendingActionsOfStrategy, + ownershipClearPendingActionsOfStrategyType, + ownershipClearPendingActionsOfStrategyQuality +] = createQualitySetWithPayload({ + type: 'clear Ownership\'s Pending Actions of Strategy Topic', + reducer: (state: OwnershipState, action) => { + const {topic} = selectPayload(action); + const newPendingActions: Action[] = []; + for (const act of state.pendingActions) { + if (act.strategy?.topic) { + if (act.strategy.topic !== topic) { + newPendingActions.push(act); + } } } + return { + ...state, + pendingActions: newPendingActions + }; } - return { - ...state, - pendingActions: newPendingActions - }; -} -export const clearPendingActionsOfStrategyQuality = createQuality( - ownershipClearPendingActionsOfStrategyType, - ownershipClearPendingActionsOfStrategyReducer, - defaultMethodCreator -); +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/ownership/qualities/clearStrategyStubsFromLedgerAndSelf.quality.ts b/src/concepts/ownership/qualities/clearStrategyStubsFromLedgerAndSelf.quality.ts index 2c519c3..487218d 100644 --- a/src/concepts/ownership/qualities/clearStrategyStubsFromLedgerAndSelf.quality.ts +++ b/src/concepts/ownership/qualities/clearStrategyStubsFromLedgerAndSelf.quality.ts @@ -4,53 +4,50 @@ generate a quality that will clear the current strategies stubs from the ownership ledger. This is to afford for strategies to relieve their ownership prior to their conclusion. $>*/ /*<#*/ -import { MethodCreator, createQuality } from '../../../model/concept'; -import { Action, ActionType, prepareActionCreator } from '../../../model/action'; import { OwnershipState } from '../ownership.concept'; import { OwnershipTicket } from '../../../model/ownership'; import { strategySuccess } from '../../../model/actionStrategy'; -import { createMethod } from '../../../model/method'; +import { createMethodDebounce } from '../../../model/method'; +import { createQualitySet } from '../../../model/quality'; -export const ownershipClearStrategyStubsFromLedgerAndSelfType: ActionType = 'clear current Strategy Stubs from Ownership Ledger and Itself'; -export const ownershipClearStrategyStubsFromLedgerAndSelf = prepareActionCreator(ownershipClearStrategyStubsFromLedgerAndSelfType); - -const ownershipClearStrategyStubsFromLedgerAndSelfMethodCreator: MethodCreator = () => createMethod((action) => { - if (action.strategy) { - action.strategy.stubs = undefined; - return strategySuccess(action.strategy); - } - return action; -}); - -function ownershipClearStrategyStubsFromLedgerAndSelfReducer(state: OwnershipState, action: Action): OwnershipState { - const stubs = action?.strategy?.stubs; - const ownershipLedger = state.ownershipLedger; - if (action.strategy && stubs) { - stubs.forEach(ticketStub => { - const line = ownershipLedger.get(ticketStub.key); - if (line) { - const newLine = [] as OwnershipTicket[]; - for (const stub of line) { - if (stub.ticket !== ticketStub.ticket) { - newLine.push(stub); +export const [ + ownershipClearStrategyStubsFromLedgerAndSelf, + ownershipClearStrategyStubsFromLedgerAndSelfType, + ownershipClearStrategyStubsFromLedgerAndSelfQuality +] = createQualitySet({ + type: 'clear current Strategy Stubs from Ownership Ledger and Itself', + reducer: (state: OwnershipState, action) => { + const stubs = action?.strategy?.stubs; + const ownershipLedger = state.ownershipLedger; + if (action.strategy && stubs) { + stubs.forEach(ticketStub => { + const line = ownershipLedger.get(ticketStub.key); + if (line) { + const newLine = [] as OwnershipTicket[]; + for (const stub of line) { + if (stub.ticket !== ticketStub.ticket) { + newLine.push(stub); + } + } + if (newLine.length === 0) { + ownershipLedger.delete(ticketStub.key); + } else { + ownershipLedger.set(ticketStub.key, newLine); } } - if (newLine.length === 0) { - ownershipLedger.delete(ticketStub.key); - } else { - ownershipLedger.set(ticketStub.key, newLine); - } - } - }); - } - return { - ...state, - ownershipLedger: ownershipLedger - }; -} -export const clearStrategyStubsFromLedgerAndSelfQuality = createQuality( - ownershipClearStrategyStubsFromLedgerAndSelfType, - ownershipClearStrategyStubsFromLedgerAndSelfReducer, - ownershipClearStrategyStubsFromLedgerAndSelfMethodCreator -); + }); + } + return { + ...state, + ownershipLedger: ownershipLedger + }; + }, + methodCreator: () => createMethodDebounce((action) => { + if (action.strategy) { + action.strategy.stubs = undefined; + return strategySuccess(action.strategy); + } + return action; + }, 10) +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/ownership/qualities/initializeOwnership.quality.ts b/src/concepts/ownership/qualities/initializeOwnership.quality.ts index 076df4c..e458e40 100644 --- a/src/concepts/ownership/qualities/initializeOwnership.quality.ts +++ b/src/concepts/ownership/qualities/initializeOwnership.quality.ts @@ -3,22 +3,17 @@ For the asynchronous graph programming framework Stratimux and Ownership Concept generate a quality that will simply set ownership's initialized property to true. $>*/ /*<#*/ -import { createQuality, defaultMethodCreator } from '../../../model/concept'; -import { Action, ActionType, prepareActionCreator } from '../../../model/action'; +import { defaultMethodCreator } from '../../../model/concept'; import { OwnershipState } from '../ownership.concept'; +import { createQualitySet } from '../../../model/quality'; -export const ownershipInitializeOwnershipType: ActionType = 'Ownership Initialize to True to enable Ownership Principle'; -export const ownershipInitializeOwnership = prepareActionCreator(ownershipInitializeOwnershipType); - -export function ownershipInitializeOwnershipReducer(state: OwnershipState, _: Action) { - return { - ...state, - initialized: true - }; -} -export const initializeOwnershipQuality = createQuality( +export const [ + ownershipInitializeOwnership, ownershipInitializeOwnershipType, - ownershipInitializeOwnershipReducer, - defaultMethodCreator -); + ownershipInitializeOwnershipQuality +] = createQualitySet({ + type: 'Ownership Initialize to True to enable Ownership Principle', + reducer: (state: OwnershipState): OwnershipState => ({...state, initialized: true}), + methodCreator: defaultMethodCreator +}); /*#>*/ \ No newline at end of file diff --git a/src/concepts/ownership/qualities/resetOwnershipLedger.quality.ts b/src/concepts/ownership/qualities/resetOwnershipLedger.quality.ts index 7bcc80a..c573bb6 100644 --- a/src/concepts/ownership/qualities/resetOwnershipLedger.quality.ts +++ b/src/concepts/ownership/qualities/resetOwnershipLedger.quality.ts @@ -2,23 +2,18 @@ For the asynchronous graph programming framework Stratimux and Ownership Concept, generate a quality that hard resets the current ownership ledger. $>*/ /*<#*/ -import { createQuality, defaultMethodCreator } from '../../../model/concept'; -import { Action, ActionType, prepareActionCreator } from '../../../model/action'; +import { defaultMethodCreator } from '../../../model/concept'; import { OwnershipState } from '../ownership.concept'; import { createOwnershipLedger } from '../../../model/ownership'; +import { createQualitySet } from '../../../model/quality'; -export const ownershipResetOwnershipLedgerType: ActionType = 'reset Ownership Ledger'; -export const ownershipResetOwnershipLedger = prepareActionCreator(ownershipResetOwnershipLedgerType); - -function ownershipResetOwnershipLedgerReducer(state: OwnershipState, _: Action): OwnershipState { - return { - ...state, - ownershipLedger: createOwnershipLedger() - }; -} -export const resetOwnershipLedgerQuality = createQuality( +export const [ + ownershipResetOwnershipLedger, ownershipResetOwnershipLedgerType, - ownershipResetOwnershipLedgerReducer, - defaultMethodCreator -); + ownershipResetOwnershipLedgerQuality +] = createQualitySet({ + type: 'reset Ownership Ledger', + reducer: (state: OwnershipState): OwnershipState => ({...state, ownershipLedger: createOwnershipLedger()}), + methodCreator: defaultMethodCreator +}); /*#>*/ \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 5489756..382e142 100644 --- a/src/index.ts +++ b/src/index.ts @@ -97,6 +97,10 @@ export type { Mode, MethodCreator, } from './model/concept'; +export { + createQualitySet, + createQualitySetWithPayload +} from './model/quality'; export type { KeyedSelector } from './model/selector'; export { selectState, @@ -195,9 +199,10 @@ export { export { ChainState, chainName, createChainConcept } from './concepts/chain/chain.concept'; // Qualities export { - chainDispatchActions, - chainDispatchActionsType, - ChainDispatchActionsPayload, + chainPrepareChain, + chainPrepareChainType, + ChainPrepareChainPayload, + chainPrepareChainQuality } from './concepts/chain/qualities/prepareChain.quality'; export {chainEnd, chainEndType} from './concepts/chain/qualities/chainEnd.quality'; @@ -235,7 +240,7 @@ export { experimentName } from './concepts/experiment/experiment.concept'; export { - checkInStrategyQuality, + experimentCheckInStrategyQuality, experimentCheckInStrategy, experimentCheckInStrategyType } from './concepts/experiment/qualities/checkInStrategy.quality'; diff --git a/src/model/action.ts b/src/model/action.ts index b5dee99..2b4c72c 100644 --- a/src/model/action.ts +++ b/src/model/action.ts @@ -187,6 +187,13 @@ export function createAction>( }; } +export type ActionCreator = ( + conceptSemaphore?: number, + keyedSelectors?: KeyedSelector[], + agreement?: number, + qualitySemaphore?: [number, number, number, number] + ) => Action; + export function prepareActionCreator(actionType: ActionType) { return ( conceptSemaphore?: number, @@ -197,6 +204,7 @@ export function prepareActionCreator(actionType: ActionType) { return createAction(actionType, undefined, keyedSelectors, agreement, qualitySemaphore, conceptSemaphore); }; } + export function prepareActionWithPayloadCreator>(actionType: ActionType) { return ( payload: T, @@ -204,10 +212,17 @@ export function prepareActionWithPayloadCreator { + ): Action => { return createAction(actionType, payload, keyedSelectors, agreement, semaphore, conceptSemaphore); }; } +export type ActionCreatorWithPayload = ( + payload: T, + conceptSemaphore?: number, + keyedSelectors?: KeyedSelector[], + agreement?: number, + semaphore?: [number, number, number, number] + ) => Action; /** * Should only be used after if you can logically determine that the semaphores have been primed. diff --git a/src/model/quality.ts b/src/model/quality.ts new file mode 100644 index 0000000..a7a102d --- /dev/null +++ b/src/model/quality.ts @@ -0,0 +1,41 @@ +/*<$ +For the asynchronous graph programming framework Stratimux, define the Quality model file. +This model allows for qualities to be made at a single point of entry, reducing the complexity of defining such. +$>*/ + +import { ActionCreator, ActionCreatorWithPayload, prepareActionCreator, prepareActionWithPayloadCreator } from './action'; +import { MethodCreator, Quality, Reducer, createQuality } from './concept'; +import { ActionType } from './method'; +import { KeyedSelector } from './selector'; + +/*<#*/ +export function createQualitySet(q: { + type: string, + reducer: Reducer, + methodCreator?: MethodCreator, + keyedSelectors?: KeyedSelector[], + meta?: Record, + analytics?: Record +}): [ActionCreator, ActionType, Quality] { + return [ + prepareActionCreator(q.type), + q.type, + createQuality(q.type, q.reducer, q.methodCreator, q.keyedSelectors, q.meta, q.analytics) + ]; +} + +export function createQualitySetWithPayload>(q: { + type: string, + reducer: Reducer, + methodCreator?: MethodCreator, + keyedSelectors?: KeyedSelector[], + meta?: Record, + analytics?: Record +}): [ActionCreatorWithPayload, ActionType, Quality] { + return [ + prepareActionWithPayloadCreator(q.type), + q.type, + createQuality(q.type, q.reducer, q.methodCreator, q.keyedSelectors, q.meta, q.analytics) + ]; +} +/*#>*/ \ No newline at end of file diff --git a/src/test/chain.test.ts b/src/test/chain.test.ts index 42e889d..507e25f 100644 --- a/src/test/chain.test.ts +++ b/src/test/chain.test.ts @@ -8,7 +8,7 @@ import { primeAction } from '../model/action'; import { selectState } from '../model/selector'; import { CounterState, createCounterConcept, counterName } from '../concepts/counter/counter.concept'; import { ChainState, chainName, createChainConcept } from '../concepts/chain/chain.concept'; -import { chainDispatchActions } from '../concepts/chain/qualities/prepareChain.quality'; +import { chainPrepareChain } from '../concepts/chain/qualities/prepareChain.quality'; import { counterAdd } from '../concepts/counter/qualities/add.quality'; import { counterSubtract } from '../concepts/counter/qualities/subtract.quality'; import { chainEnd } from '../concepts/chain/qualities/chainEnd.quality'; @@ -26,7 +26,7 @@ test('Axium Test', (done) => { const primedEnd = primeAction(concepts, chainEnd()); const primedPrepareChain = primeAction(concepts, - chainDispatchActions({ + chainPrepareChain({ actions: [ primedAdd, primedAdd, diff --git a/src/test/debounceMethods.test.ts b/src/test/debounceMethods.test.ts index 764b05e..7f83d85 100644 --- a/src/test/debounceMethods.test.ts +++ b/src/test/debounceMethods.test.ts @@ -9,12 +9,12 @@ import { ExperimentState, createExperimentConcept, createExperimentState, experi import { experimentDebounceAsyncIterateIdThenReceiveInMethodQuality } from '../concepts/experiment/qualities/debounceAsyncIterateIdThenReceiveInMethod.quality'; -import { asyncDebounceNextActionNodeQuality } from '../concepts/experiment/qualities/debounceAsyncNextActionNode.quality'; +import { experimentAsyncDebounceNextActionNodeQuality } from '../concepts/experiment/qualities/debounceAsyncNextActionNode.quality'; import { ExperimentDebounceIterateIdThenReceiveInMethodPayload, experimentDebounceIterateIdThenReceiveInMethodQuality } from '../concepts/experiment/qualities/debounceIterateIdThenReceiveInMethod.quality'; -import { debounceNextActionNodeQuality } from '../concepts/experiment/qualities/debounceNextActionNode.quality'; +import { experimentDebounceNextActionNodeQuality } from '../concepts/experiment/qualities/debounceNextActionNode.quality'; import { experimentAsyncDebounceAddOneStrategy } from '../concepts/experiment/strategies/asyncDebounceAddOne.strategy'; import { experimentDebounceAddOneStrategy } from '../concepts/experiment/strategies/debounceAddOne.strategy'; import { @@ -31,7 +31,7 @@ import { selectSlice, selectState } from '../model/selector'; import { createStage } from '../model/stagePlanner'; test('Debounce method prevent excess count', (done) => { - const experiment = createExperimentConcept(createExperimentState(), [debounceNextActionNodeQuality]); + const experiment = createExperimentConcept(createExperimentState(), [experimentDebounceNextActionNodeQuality]); const axium = createAxium('Experiment async method creator with State', [createCounterConcept(), experiment]); const plan = axium.plan('Experiment debounce add one', [ createStage((_, dispatch) => { @@ -63,7 +63,7 @@ test('Debounce method prevent excess count', (done) => { }); test('Async debounce method prevent excess count', (done) => { - const experiment = createExperimentConcept(createExperimentState(), [asyncDebounceNextActionNodeQuality]); + const experiment = createExperimentConcept(createExperimentState(), [experimentAsyncDebounceNextActionNodeQuality]); const axium = createAxium('Experiment async debounce', [createCounterConcept(), experiment]); const plan = axium.plan('Experiment async debounce add one', [ createStage((_, dispatch) => { diff --git a/src/test/methodHelpers.test.ts b/src/test/methodHelpers.test.ts index c48c3e6..0c832da 100644 --- a/src/test/methodHelpers.test.ts +++ b/src/test/methodHelpers.test.ts @@ -10,9 +10,9 @@ import { experimentAsyncIterateIdThenReceiveInMethodQuality } from '../concepts/experiment/qualities/asyncIterateIdThenReceiveInMethod.quality'; import { experimentIterateIdThenReceiveInMethodQuality } from '../concepts/experiment/qualities/iterateIdThenReceiveInMethod.quality'; -import { mockToTrueQuality } from '../concepts/experiment/qualities/mockTrue.quality'; -import { timerEmitActionQuality } from '../concepts/experiment/qualities/timerEmitAction.quality'; -import { timerEmitActionWithStateQuality } from '../concepts/experiment/qualities/timerEmitActionWithState.quality'; +import { experimentMockToTrueQuality } from '../concepts/experiment/qualities/mockToTrue.quality'; +import { experimentTimerEmitActionQuality } from '../concepts/experiment/qualities/timerEmitAction.quality'; +import { experimentTimerEmitActionWithStateQuality } from '../concepts/experiment/qualities/timerEmitActionWithState.quality'; import { experimentAsyncIterateIdThenAddToData, experimentAsyncIterateIdThenAddToDataTopic @@ -32,7 +32,7 @@ import { selectSlice, selectState } from '../model/selector'; import { createStage, stageWaitForOpenThenIterate } from '../model/stagePlanner'; test('Async Method Test', (done) => { - const experiment = createExperimentConcept(createExperimentState(), [timerEmitActionQuality, mockToTrueQuality]); + const experiment = createExperimentConcept(createExperimentState(), [experimentTimerEmitActionQuality, experimentMockToTrueQuality]); const axium = createAxium('Experiment async method creator', [experiment]); const plan = axium.plan('timed mock to true', [ stageWaitForOpenThenIterate(() => axiumKick()), @@ -79,7 +79,7 @@ test('Async Method Plain Iterate Id Test', (done) => { }); test('Async Method with State Test', (done) => { - const experiment = createExperimentConcept(createExperimentState(), [timerEmitActionWithStateQuality, mockToTrueQuality]); + const experiment = createExperimentConcept(createExperimentState(), [experimentTimerEmitActionWithStateQuality, experimentMockToTrueQuality]); const axium = createAxium('Experiment async method creator with State', [experiment]); const plan = axium.plan('timed mock to true', [ stageWaitForOpenThenIterate(() => axiumKick()), diff --git a/src/test/ownership.test.ts b/src/test/ownership.test.ts index dae1476..ef3bed4 100644 --- a/src/test/ownership.test.ts +++ b/src/test/ownership.test.ts @@ -4,7 +4,7 @@ $>*/ /*<#*/ import { createAxium } from '../model/axium'; import { Concepts } from '../model/concept'; -import { selectConcept, selectSlice, selectState } from '../model/selector'; +import { selectConcept, selectState } from '../model/selector'; import { OwnershipState, createOwnershipConcept, ownershipName } from '../concepts/ownership/ownership.concept'; import { AxiumState } from '../concepts/axium/axium.concept'; import { ownershipSetOwnerShipModeTopic } from '../concepts/ownership/strategies/setOwnerShipMode.strategy'; @@ -19,10 +19,9 @@ import { } from '../concepts/experiment/strategies/experimentCounting.strategy'; import { axiumLog } from '../concepts/axium/qualities/log.quality'; import { counterSetCount } from '../concepts/counter/qualities/setCount.quality'; -import { checkInStrategyQuality } from '../concepts/experiment/qualities/checkInStrategy.quality'; +import { experimentCheckInStrategyQuality } from '../concepts/experiment/qualities/checkInStrategy.quality'; import { experimentActionQuePrinciple } from '../concepts/experiment/experiment.principle'; import { createStage } from '../model/stagePlanner'; -import { axiumSelectOpen } from '../concepts/axium/axium.selector'; test('Ownership Test', (done) => { const orderOfTopics: string[] = []; @@ -30,7 +29,7 @@ test('Ownership Test', (done) => { const axium = createAxium('ownershipTest', [ createOwnershipConcept(), createCounterConcept(), - createExperimentConcept(createExperimentState(), [checkInStrategyQuality], [experimentActionQuePrinciple]) + createExperimentConcept(createExperimentState(), [experimentCheckInStrategyQuality], [experimentActionQuePrinciple]) ], true, true); const plan = axium.plan( 'Testing Ownership Staging', [