Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

createPayload and selectPayload #73

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ActionStrategy.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface ActionNode {
```
* action - Is an union data pattern to bind the functionality of the ActionNode, ActionStrategy, and Action. This allows for each part to be responsible for itself and to allow for additional functionality at runtime.
* actionType - Is merely the type of action to be created at runtime, these should be verbose as to their intended effect as it informs the STRX sentence structure's body.
* payload - Is set to unknown to allow for the explicit typecasting during consumption, reducer, method, or principle.
* payload - Is set to unknown to allow for the explicit typecasting during consumption, reducer, method, or principle. Use createPayload<_Type>(payload: _Type) to ensure type casting in the reducer will be the same type as used in createPayload. This is a logical determination in line with Javascript core functionality.
* keyedSelectors - An Array of KeyedSelector that locks some property during the life time of the created action.
* semaphore - First is concept's index, second is the quality's index, and the final is the generation of the sets of concepts currently stored on the Axium. *Explicitly setting this value, denotes a primed action without additional look up at runtime.*
* agreement - Is time in milliseconds of the lock's expiration time. Default is currently 5000, but such will be reduced upon testing and feedback.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const staged = axium.stage(
// Will be ran after both counting strategies conclude.
const ownership = selectState<OwnershipState>(cpts, ownershipName);
console.log('Stage 2', ownership.ownershipLedger, ownership.pendingActions);
dispatch(counterSetCount({newCount: 1000}, undefined, 7000), { iterateStep: true});
dispatch(counterSetCount(createPayload<SetCountPayload>({newCount: 1000}), undefined, 7000), { iterateStep: true});
},
(cpts, dispatch) => {
const ownership = selectState<OwnershipState>(cpts, ownershipName);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@phuire/strx",
"version": "0.0.20",
"version": "0.0.21",
"description": "Unified Turing Machine",
"main": "dist/index.js",
"module": "dist/index.mjs",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { createAction } from '../../../model/action';
import { createQuality } from '../../../model/concept';
import { AxiumState } from '../axium.concept';
import { axiumConcludeType } from './conclude.quality';
import { selectPayload } from '../../../model/selector';

export const axiumAppendActionListToDialogType: ActionType = 'append Action List to Axium\'s Dialog';

Expand Down Expand Up @@ -37,7 +38,7 @@ const createAppendActionListToDialogMethodCreator: MethodCreator = () => {
};

export function appendActionListToDialogReducer(state: AxiumState, action: Action) {
const payload = action.payload as AppendActionListToDialogPayload;
const payload = selectPayload<AppendActionListToDialogPayload>(action);
let newDialog = '';
if (state.storeDialog) {
payload.actionList.forEach(str => {newDialog += str + ' ';});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Concept, defaultMethodCreator } from '../../../model/concept';
import { AxiumState } from '../axium.concept';
import { Action, ActionType } from '../../../model/action';
import { createQuality } from '../../../model/concept';
import { selectPayload } from '../../../model/selector';

export const axiumAppendConceptsToAddQueType: ActionType = 'append Concepts to Axium\'s Add Concept Que';

Expand All @@ -10,7 +11,7 @@ export type AppendConceptsToAddQuePayload = {
}

export function appendConceptsToAddQueReducer(state: AxiumState, action: Action) {
const payload = action.payload as AppendConceptsToAddQuePayload;
const payload = selectPayload<AppendConceptsToAddQuePayload>(action);
const addConceptQue = [
...payload.concepts
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Concept, defaultMethodCreator } from '../../../model/concept';
import { AxiumState } from '../axium.concept';
import { Action, ActionType } from '../../../model/action';
import { createQuality } from '../../../model/concept';
import { selectPayload } from '../../../model/selector';

export const axiumAppendConceptsToRemoveQueType: ActionType = 'append Concepts to Axium\'s Remove Concept Que';

Expand All @@ -10,7 +11,7 @@ export type AppendConceptsToRemoveQuePayload = {
}

export function appendConceptsToRemoveQueReducer(state: AxiumState, action: Action) {
const payload = action.payload as AppendConceptsToRemoveQuePayload;
const payload = selectPayload<AppendConceptsToRemoveQuePayload>(action);
let removeQue = state.removeConceptQue;
removeQue = [
...removeQue,
Expand Down
3 changes: 2 additions & 1 deletion src/concepts/axium/qualities/badAction.quality.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Action, ActionType } from '../../../model/action';
import { createQuality } from '../../../model/concept';
import { selectPayload } from '../../../model/selector';
import { AxiumState } from '../axium.concept';

export const axiumBadActionType: ActionType = 'Axium received a Bad Action';
export type BadActionPayload = Action[];

export function badActionReducer(state: AxiumState, action: Action) {
const payload = action.payload as BadActionPayload;
const payload = selectPayload<BadActionPayload>(action);
if (state.logging) {
console.log('Axium Received a Bad Action: ', action);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { defaultMethodCreator, createQuality } from '../../../model/concept';
import { Action, ActionType, prepareActionCreator } from '../../../model/action';
import { AxiumState } from '../axium.concept';
import { selectPayload } from '../../../model/selector';

export const axiumClearBadActionTypeFromBadActionListType: ActionType = 'clear ActionType from Axium\'s badAction list';
export const axiumClearBadActionTypeFromBadActionList = prepareActionCreator(axiumClearBadActionTypeFromBadActionListType);
export type ClearBadActionTypeFromBadActionListPayload = ActionType;

function clearBadActionTypeFromBadActionListReducer(state: AxiumState, action: Action): AxiumState {
const actionType = action.payload as ClearBadActionTypeFromBadActionListPayload;
const actionType = selectPayload<ClearBadActionTypeFromBadActionListPayload>(action);
return {
...state,
badActions: state.badActions.filter(act => act.type !== actionType),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { defaultMethodCreator, createQuality } from '../../../model/concept';
import { Action, ActionType, prepareActionCreator } from '../../../model/action';
import { AxiumState } from '../axium.concept';
import { selectPayload } from '../../../model/selector';

export const axiumClearBadPlanFromBadPlanListType: ActionType = 'clear Plan Topic from Axium\'s badPlan list';
export const axiumClearBadPlanFromBadPlanList = prepareActionCreator(axiumClearBadPlanFromBadPlanListType);
export type ClearBadPlanFromBadPlanListPayload = string;

function clearBadPlanFromBadPlanListReducer(state: AxiumState, action: Action): AxiumState {
const title = action.payload as ClearBadPlanFromBadPlanListPayload;
const title = selectPayload<ClearBadPlanFromBadPlanListPayload>(action);
return {
...state,
badPlans: state.badPlans.filter(act => act.title !== title),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { defaultMethodCreator, createQuality } from '../../../model/concept';
import { Action, ActionType, prepareActionCreator } from '../../../model/action';
import { AxiumState } from '../axium.concept';
import { selectPayload } from '../../../model/selector';

export const axiumClearBadStrategyTopicFromBadActionListType: ActionType = 'clear Strategy Topic from Axium\'s badAction list';
export const axiumClearBadStrategyTopicFromBadActionList = prepareActionCreator(axiumClearBadStrategyTopicFromBadActionListType);
export type ClearBadStrategyTopicFromBadActionListPayload = string;

function clearBadStrategyTopicFromBadActionListReducer(state: AxiumState, action: Action): AxiumState {
const strategyTopic = action.payload as ClearBadStrategyTopicFromBadActionListPayload;
const strategyTopic = selectPayload<ClearBadStrategyTopicFromBadActionListPayload>(action);
const badActions = state.badActions.filter(act => {
if (act.strategy && act.strategy.topic !== strategyTopic) {
return true;
Expand Down
3 changes: 2 additions & 1 deletion src/concepts/axium/qualities/initializePrinciples.quality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Action, ActionType } from '../../../model/action';
import { AxiumState } from '../axium.concept';
import { createQuality } from '../../../model/concept';
import { UnifiedSubject } from '../../../model/unifiedSubject';
import { selectPayload } from '../../../model/selector';

export const axiumInitializePrinciplesType: ActionType = 'initialize Principles and set new Subscribers to General Subscribers list';

Expand All @@ -13,7 +14,7 @@ export type InitializePrinciplesPayload = {
}

export function initializePrinciplesReducer(state: AxiumState, _action: Action) {
const payload = _action.payload as InitializePrinciplesPayload;
const payload = selectPayload<InitializePrinciplesPayload>(_action);
const concepts = payload.concepts;
const action$ = state.action$ as Subject<Action>;
const subConcepts$ = state.concepts$ as UnifiedSubject;
Expand Down
4 changes: 3 additions & 1 deletion src/concepts/axium/qualities/open.quality.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { defaultMethodCreator, createQuality } from '../../../model/concept';
import { Action, ActionType, prepareActionCreator } from '../../../model/action';
import { AxiumState } from '../axium.concept';
import { selectPayload } from '../../../model/selector';

export const axiumOpenType: ActionType = 'Open Axium';
export const axiumOpen = prepareActionCreator(axiumOpenType);

export type OpenPayload = {
open?: boolean;
} | undefined;

export function openReducer(state: AxiumState, action: Action) {
const payload = action.payload as OpenPayload;
const payload = selectPayload<OpenPayload>(action);
return {
...state,
open: payload?.open ? payload.open : true
Expand Down
3 changes: 2 additions & 1 deletion src/concepts/axium/qualities/registerSubscriber.quality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { defaultMethodCreator } from '../../../model/concept';
import { Action, ActionType } from '../../../model/action';
import { AxiumState } from '../axium.concept';
import { createQuality } from '../../../model/concept';
import { selectPayload } from '../../../model/selector';

export const axiumRegisterSubscriberType: ActionType = 'register Subscriber to Axium\'s General Subscriber list';

Expand All @@ -12,7 +13,7 @@ export type RegisterSubscriberPayload = {
}

export function registerSubscriberReducer(state: AxiumState, action: Action) {
const payload = action.payload as RegisterSubscriberPayload;
const payload = selectPayload<RegisterSubscriberPayload>(action);
const generalSubscribers = state.generalSubscribers;
const subscriber = payload.subscriber;
const name = payload.name;
Expand Down
3 changes: 2 additions & 1 deletion src/concepts/axium/qualities/setBlockingMode.quality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Action, ActionType } from '../../../model/action';
import { AxiumState } from '../axium.concept';
import { createQuality } from '../../../model/concept';
import { blockingMethodSubscription } from '../../../model/axium';
import { selectPayload } from '../../../model/selector';

export const axiumSetBlockingModeType: ActionType = 'set Axium to Blocking Mode';

Expand All @@ -16,7 +17,7 @@ export function setBlockingModeReducer(state: AxiumState, _action: Action) {
methodSubscribers.forEach(named => named.subscriber.unsubscribe());
methodSubscribers = [];

const payload = _action.payload as SetBlockingModePayload;
const payload = selectPayload<SetBlockingModePayload>(_action);
const concepts = payload.concepts;
concepts.forEach(concept => {
concept.qualities.forEach(quality => {
Expand Down
3 changes: 2 additions & 1 deletion src/concepts/axium/qualities/setDefaultMode.quality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Action, ActionType } from '../../../model/action';
import { AxiumState } from '../axium.concept';
import { createQuality } from '../../../model/concept';
import { defaultMethodSubscription } from '../../../model/axium';
import { selectPayload } from '../../../model/selector';

export const axiumSetDefaultModeType: ActionType = 'set Axium to its current Default Mode Index';

Expand All @@ -15,7 +16,7 @@ export function setDefaultModeReducer(state: AxiumState, _action: Action) {
let methodSubscribers = state.methodSubscribers;
methodSubscribers.forEach(named => named.subscriber.unsubscribe());
methodSubscribers = [];
const payload = _action.payload as SetDefaultModePayload;
const payload = selectPayload<SetDefaultModePayload>(_action);
const concepts = payload.concepts;
concepts.forEach(concept => {
concept.qualities.forEach(quality => {
Expand Down
3 changes: 2 additions & 1 deletion src/concepts/axium/qualities/setDefaultModeIndex.quality.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defaultMethodCreator, createQuality } from '../../../model/concept';
import { Action, ActionType } from '../../../model/action';
import { AxiumState } from '../axium.concept';
import { selectPayload } from '../../../model/selector';

export const axiumSetDefaultModeIndexType: ActionType = 'set Axium\'s Default Mode Index';

Expand All @@ -9,7 +10,7 @@ export type SetDefaultModeIndexPayload = {
};

export function setDefaultModeIndexReducer(state: AxiumState, action: Action) {
const payload = action.payload as SetDefaultModeIndexPayload;
const payload = selectPayload<SetDefaultModeIndexPayload>(action);
return {
...state,
defaultModeIndex: payload.index,
Expand Down
3 changes: 2 additions & 1 deletion src/concepts/axium/qualities/setMode.quality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { createQuality, MethodCreator, Method } from '../../../model/concept';
import { Subject, map } from 'rxjs';
import { axiumConcludeType } from './conclude.quality';
import { strategySuccess } from '../../../model/actionStrategy';
import { selectPayload } from '../../../model/selector';

export const axiumSetModeType = 'set Axium Mode';

Expand All @@ -30,7 +31,7 @@ export const createOwnershipMethodCreator: MethodCreator = () : [Method, Subject
};

export function setModeReducer(state: AxiumState, _action: Action) {
const payload = _action.payload as SetModePayload;
const payload = selectPayload<SetModePayload>(_action);
return {
...state,
modeIndex: [payload.modeIndex],
Expand Down
11 changes: 6 additions & 5 deletions src/concepts/axium/strategies/addConcept.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import { AddConceptsFromQuePayload, axiumAddConceptFromQueType } from '../qualit
import { AppendConceptsToAddQuePayload, axiumAppendConceptsToAddQueType } from '../qualities/appendConceptsToAddQue.quality';
import { axiumOpenType } from '../qualities/open.quality';
import { axiumSetBlockingModeType } from '../qualities/setBlockingMode.quality';
import { axiumSetDefaultModeType } from '../qualities/setDefaultMode.quality';
import { SetDefaultModePayload, axiumSetDefaultModeType } from '../qualities/setDefaultMode.quality';
import { axiumName } from '../axium.concept';
import { createPayload } from '../../../model/selector';

// Step One to Add Concepts to Axium
export const addConceptsToAddQueThenBlockTopic = 'Add Concepts to add que then set Axium Mode to Blocking';
Expand All @@ -20,7 +21,7 @@ export function addConceptsToAddQueThenBlockStrategy(concepts: Concept[], newCon
},
failureNode: null,
semaphore: getSemaphore(concepts, axiumName, axiumAppendConceptsToAddQueType),
payload: {concepts: newConcepts} as AppendConceptsToAddQuePayload,
payload: createPayload<AppendConceptsToAddQuePayload>({concepts: newConcepts}),
};
const stepOne: ActionNode = {
actionType: axiumSetBlockingModeType,
Expand All @@ -30,7 +31,7 @@ export function addConceptsToAddQueThenBlockStrategy(concepts: Concept[], newCon
},
failureNode: null,
semaphore: getSemaphore(concepts, axiumName, axiumSetBlockingModeType),
payload: {concepts} as AppendConceptsToAddQuePayload,
payload: createPayload<AppendConceptsToAddQuePayload>({concepts}),
};

const params: ActionStrategyParameters = {
Expand Down Expand Up @@ -64,7 +65,7 @@ export function addConceptsFromQueThenUnblockStrategy(action$: Subject<Action>,
preposition: 'Then'
},
failureNode: null,
payload: {concepts: conceptualSet},
payload: createPayload<SetDefaultModePayload>({concepts: conceptualSet}),
};
const stepOne: ActionNode = {
actionType: axiumAddConceptFromQueType,
Expand All @@ -74,7 +75,7 @@ export function addConceptsFromQueThenUnblockStrategy(action$: Subject<Action>,
preposition: 'First'
},
failureNode: null,
payload: {action$} as AddConceptsFromQuePayload,
payload: createPayload<AddConceptsFromQuePayload>({action$}),
};

const params: ActionStrategyParameters = {
Expand Down
13 changes: 7 additions & 6 deletions src/concepts/axium/strategies/initialization.strategy.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { createStrategy, ActionNode, ActionStrategy, ActionStrategyParameters } from '../../../model/actionStrategy';
import { Concept } from '../../../model/concept';
import { getSemaphore } from '../../../model/action';
import { axiumOpenType } from '../qualities/open.quality';
import { axiumInitializePrinciplesType } from '../qualities/initializePrinciples.quality';
import { axiumSetDefaultModeType } from '../qualities/setDefaultMode.quality';
import { OpenPayload, axiumOpenType } from '../qualities/open.quality';
import { InitializePrinciplesPayload, axiumInitializePrinciplesType } from '../qualities/initializePrinciples.quality';
import { SetDefaultModePayload, axiumSetDefaultModeType } from '../qualities/setDefaultMode.quality';
import { axiumName } from '../axium.concept';
import { createPayload } from '../../../model/selector';

export const initializeTopic = 'Axium Initialization Strategy';
export function initializationStrategy(concepts: Concept[]): ActionStrategy {
Expand All @@ -21,7 +22,7 @@ export function initializationStrategy(concepts: Concept[]): ActionStrategy {
denoter: 'to Notify Subscribers of State changes.'
},
failureNode: null,
payload: {concepts},
payload: createPayload<OpenPayload>({open: true}),
};
const stepTwo: ActionNode = {
actionType: axiumSetDefaultModeType,
Expand All @@ -31,7 +32,7 @@ export function initializationStrategy(concepts: Concept[]): ActionStrategy {
preposition: 'Then'
},
failureNode: null,
payload: {concepts},
payload: createPayload<SetDefaultModePayload>({concepts}),
};
const stepOne: ActionNode = {
actionType: axiumInitializePrinciplesType,
Expand All @@ -41,7 +42,7 @@ export function initializationStrategy(concepts: Concept[]): ActionStrategy {
preposition: 'Begin with'
},
failureNode: null,
payload: {concepts},
payload: createPayload<InitializePrinciplesPayload>({concepts}),
};

const params: ActionStrategyParameters = {
Expand Down
7 changes: 4 additions & 3 deletions src/concepts/axium/strategies/removeConcept.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { SetBlockingModePayload, axiumSetBlockingModeType } from '../qualities/s
import { axiumOpenType } from '../qualities/open.quality';
import { SetDefaultModePayload, axiumSetDefaultModeType } from '../qualities/setDefaultMode.quality';
import { axiumName } from '../axium.concept';
import { createPayload } from '../../../model/selector';

export const addConceptsToRemovalQueThenBlockTopic = 'Add Concepts to removal Que then set Axium Mode to Blocking';
export function addConceptsToRemovalQueThenBlockStrategy(concepts: Concept[], targetConcepts: Concept[]) {
Expand All @@ -18,14 +19,14 @@ export function addConceptsToRemovalQueThenBlockStrategy(concepts: Concept[], ta
semaphore: appendConceptsToRemoveQueSemaphore,
successNode: null,
failureNode: null,
payload: {concepts: targetConcepts} as AppendConceptsToRemoveQuePayload
payload: createPayload<AppendConceptsToRemoveQuePayload>({concepts: targetConcepts})
};
const stepOne: ActionNode = {
actionType: axiumSetBlockingModeType,
semaphore: setBlockingModeSemaphore,
successNode: stepTwo,
failureNode: null,
payload: {concepts} as SetBlockingModePayload
payload: createPayload<SetBlockingModePayload>({concepts})
};
const params: ActionStrategyParameters = {
topic: addConceptsToRemovalQueThenBlockTopic,
Expand Down Expand Up @@ -58,7 +59,7 @@ export function removeConceptsViaQueThenUnblockStrategy(concepts: Concept[]): Ac
preposition: 'Then'
},
failureNode: null,
payload: {concepts} as SetDefaultModePayload,
payload: createPayload<SetDefaultModePayload>({concepts}),
};
const stepOne: ActionNode = {
actionType: axiumRemoveConceptsViaQueType,
Expand Down
Loading