Skip to content

Commit

Permalink
Updated principles and added register StagePlanner
Browse files Browse the repository at this point in the history
  • Loading branch information
REllEK-IO committed Oct 12, 2023
1 parent f59db89 commit e4b3b18
Show file tree
Hide file tree
Showing 23 changed files with 306 additions and 204 deletions.
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.26",
"version": "0.0.27",
"description": "Unified Turing Machine",
"main": "dist/index.js",
"module": "dist/index.mjs",
Expand Down
22 changes: 13 additions & 9 deletions src/concepts/axium/axium.concept.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Subject, Subscriber } from 'rxjs';
import { Subject, Subscription } from 'rxjs';
import { Concept } from '../../model/concept';
import { Action } from '../../model/action';
import { axiumPrinciple } from './axium.principle';
Expand All @@ -7,7 +7,7 @@ import { openQuality } from './qualities/open.quality';
import { badActionQuality } from './qualities/badAction.quality';
import { closeQuality } from './qualities/close.quality';
import { logQuality } from './qualities/log.quality';
import { registerSubscriberQuality } from './qualities/registerSubscriber.quality';
import { registerSubscriberQuality } from './qualities/registerSubscription.quality';
import { initializePrinciplesQuality } from './qualities/initializePrinciples.quality';
export { initializationStrategy } from './strategies/initialization.strategy';
import { setBlockingModeQuality } from './qualities/setBlockingMode.quality';
Expand All @@ -21,14 +21,15 @@ import { createConcept } from '../../model/concept';
import { setModeQuality } from './qualities/setMode.quality';
import { setDefaultModeIndexQuality } from './qualities/setDefaultModeIndex.quality';
import { clearDialogQuality } from './qualities/clearDialog.quality';
import { Plan, UnifiedSubject } from '../../model/unifiedSubject';
import { NamedStagePlanner, Plan, UnifiedSubject } from '../../model/stagePlanner';
import { clearBadActionTypeFromBadActionListQuality } from './qualities/clearBadActionTypeFromBadActionList.quality';
import { clearBadStrategyTopicFromBadActionListQuality } from './qualities/clearBadStrategyTopicFromBadActionList.quality';
import { clearBadPlanFromBadPlanListQuality } from './qualities/clearBadPlanFromBadPlanList.quality';
import { registerStagePlannerQuality } from './qualities/registerStagePlanner.quality';

export type NamedSubscriber = {
export type NamedSubscription = {
name: string;
subscriber: Subscriber<Action>;
subscription: Subscription;
}

export type AxiumState = {
Expand All @@ -44,8 +45,9 @@ export type AxiumState = {
modeIndex: number;
defaultModeIndex: number;
modeNames: string[]
methodSubscribers: NamedSubscriber[];
generalSubscribers: NamedSubscriber[];
methodSubscribers: NamedSubscription[];
generalSubscribers: NamedSubscription[];
stagePlanners: NamedStagePlanner[];
action$: Subject<Action>;
concepts$: UnifiedSubject;
addConceptQue: Concept[],
Expand All @@ -70,8 +72,9 @@ const createAxiumState = (name: string, storeDialog?: boolean, logging?: boolean
modeIndex: 0,
defaultModeIndex: 1,
modeNames: [axiumName, axiumName],
methodSubscribers: [] as NamedSubscriber[],
generalSubscribers: [] as NamedSubscriber[],
methodSubscribers: [] as NamedSubscription[],
generalSubscribers: [] as NamedSubscription[],
stagePlanners: [] as NamedStagePlanner[],
action$: new Subject<Action>(),
concepts$: new UnifiedSubject(),
addConceptQue: [] as Concept[],
Expand All @@ -94,6 +97,7 @@ export const createAxiumConcept = (name: string, storeDialog?: boolean, logging?
clearDialogQuality,
logQuality,
registerSubscriberQuality,
registerStagePlannerQuality,
initializePrinciplesQuality,
setBlockingModeQuality,
setDefaultModeQuality,
Expand Down
2 changes: 1 addition & 1 deletion src/concepts/axium/axium.mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { axiumBadActionType } from './qualities/badAction.quality';
import { Concept } from '../../model/concept.js';
import { axiumSetBlockingModeType } from './qualities/setBlockingMode.quality';
import { axiumConcludeType } from './qualities/conclude.quality';
import { UnifiedSubject } from '../../model/unifiedSubject';
import { UnifiedSubject } from '../../model/stagePlanner';

export const isActionable = (axiumState: AxiumState, action: Action): boolean => {
let actionable = true;
Expand Down
14 changes: 5 additions & 9 deletions src/concepts/axium/axium.principle.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { Subject, Subscriber } from 'rxjs';
import { Concept, Mode } from '../../model/concept';
import { PrincipleFunction, createPrinciple$ } from '../../model/principle';
import { Action, createAction, createCacheSemaphores } from '../../model/action';
import { PrincipleFunction, registerPrincipleSubscription } from '../../model/principle';
import { Action, createCacheSemaphores } from '../../model/action';
import { AxiumState, axiumName } from './axium.concept';
import { RegisterSubscriberPayload, axiumRegisterSubscriberType } from './qualities/registerSubscriber.quality';
import { primeAction } from '../../model/action';
import { strategyBegin } from '../../model/actionStrategy';
import { addConceptsFromQueThenUnblockStrategy } from './strategies/addConcept.strategy';
import { removeConceptsViaQueThenUnblockStrategy } from './strategies/removeConcept.strategy';
import { blockingMode, permissiveMode } from './axium.mode';
import { UnifiedSubject } from '../../model/unifiedSubject';
import { UnifiedSubject } from '../../model/stagePlanner';

export const axiumPrinciple: PrincipleFunction = (
observer: Subscriber<Action>,
Expand All @@ -18,7 +16,7 @@ export const axiumPrinciple: PrincipleFunction = (
) => {
let allowAdd = true;
let allowRemove = true;
const subscriber = concepts$.subscribe(_concepts => {
const subscription = concepts$.subscribe(_concepts => {
const axiumState = _concepts[0].state as AxiumState;
if (axiumState.addConceptQue.length === 0) {
allowAdd = true;
Expand Down Expand Up @@ -97,7 +95,5 @@ export const axiumPrinciple: PrincipleFunction = (
));
}
});
const primedRegisterSubscriber = primeAction(concepts, createAction(axiumRegisterSubscriberType));
primedRegisterSubscriber.payload = { subscriber, name: axiumName } as RegisterSubscriberPayload;
observer.next(primedRegisterSubscriber);
registerPrincipleSubscription(observer, concepts, axiumName, subscription);
};
2 changes: 1 addition & 1 deletion src/concepts/axium/qualities/addConceptsFromQue.quality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function addConceptsFromQueReducer(state: AxiumState, _ : Action) {
const action$ = state.action$ as Subject<Action>;
blockingMethodSubscription(action$, action);
}) as Subscriber<Action>;
methodSubscribers.push({name: concept.name, subscriber: methodSub});
methodSubscribers.push({name: concept.name, subscription: methodSub});
}
});
});
Expand Down
12 changes: 7 additions & 5 deletions src/concepts/axium/qualities/close.quality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@ import { AxiumState } from '../axium.concept';
export const axiumCloseType: ActionType = 'Close Axium';
export const axiumClose = prepareActionCreator(axiumCloseType);

export function closeReducer(state: AxiumState, _action: Action) {
state.generalSubscribers.forEach(named => named.subscriber.unsubscribe());
state.methodSubscribers.forEach(named => named.subscriber.unsubscribe());
export function closeReducer(state: AxiumState, _action: Action): AxiumState {
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.subConcepts$.complete();
return {
...state,
methodSubscribers: [],
generalSubscribers: []
generalSubscribers: [],
stagePlanners: [],
};
}

export const closeQuality = createQuality(
axiumCloseType,
closeReducer
);
);
4 changes: 2 additions & 2 deletions src/concepts/axium/qualities/initializePrinciples.quality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createPrinciple$ } from '../../../model/principle';
import { Action, ActionType, prepareActionWithPayloadCreator } from '../../../model/action';
import { AxiumState } from '../axium.concept';
import { createQuality } from '../../../model/concept';
import { UnifiedSubject } from '../../../model/unifiedSubject';
import { UnifiedSubject } from '../../../model/stagePlanner';
import { selectPayload } from '../../../model/selector';

export type InitializePrinciplesPayload = {
Expand All @@ -26,7 +26,7 @@ export function initializePrinciplesReducer(state: AxiumState, _action: Action)
const observable = createPrinciple$(principle, concepts, subConcepts$);
subscribers.push({
name: concept.name,
subscriber: observable.subscribe((action: Action) => action$.next(action)) as Subscriber<Action>,
subscription: observable.subscribe((action: Action) => action$.next(action)) as Subscriber<Action>,
});
});
}
Expand Down
32 changes: 32 additions & 0 deletions src/concepts/axium/qualities/registerStagePlanner.quality.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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';

export type RegisterStagePlannerPayload = {
stagePlanner: StagePlanner;
conceptName: string;
}
export const axiumRegisterStagePlannerType: ActionType = 'register Stage Planner to Axium\'s Named Stage Planner list';
export const axiumRegisterStagePlanner =
prepareActionWithPayloadCreator<RegisterStagePlannerPayload>(axiumRegisterStagePlannerType);

export function registerSubscriberReducer(state: AxiumState, action: Action): AxiumState {
const payload = selectPayload<RegisterStagePlannerPayload>(action);
const stagePlanners = state.stagePlanners;
const stagePlanner = payload.stagePlanner;
const name = payload.conceptName;
stagePlanners.push({name, ...stagePlanner});
return {
...state,
stagePlanners,
};
}

export const registerStagePlannerQuality = createQuality(
axiumRegisterStagePlannerType,
registerSubscriberReducer,
defaultMethodCreator
);
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Subscriber } from 'rxjs';
import { Subscriber, 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';

export type RegisterSubscriberPayload = {
subscriber: Subscriber<Action>;
subscription: Subscription;
name: string;
}
export const axiumRegisterSubscriberType: ActionType = 'register Subscriber to Axium\'s General Subscriber list';
Expand All @@ -16,9 +16,9 @@ export const axiumRegisterSubscriber =
export function registerSubscriberReducer(state: AxiumState, action: Action) {
const payload = selectPayload<RegisterSubscriberPayload>(action);
const generalSubscribers = state.generalSubscribers;
const subscriber = payload.subscriber;
const subscription = payload.subscription;
const name = payload.name;
generalSubscribers.push({name, subscriber});
generalSubscribers.push({name, subscription});
return {
...state,
generalSubscribers,
Expand Down
29 changes: 23 additions & 6 deletions src/concepts/axium/qualities/removeConceptsViaQue.quality.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { defaultMethodCreator } from '../../../model/concept';
import { NamedSubscriber } from '../axium.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';

export const axiumRemoveConceptsViaQueType: ActionType = 'remove Concepts via Axium\'s Removal Concept Que';
export const axiumRemoveConceptsViaQue = prepareActionCreator(axiumRemoveConceptsViaQueType);

export function removeConceptsViaQueReducer(state: AxiumState, _action: Action) {
const methodSubscribers = state.methodSubscribers;
const newMethodSubscribers = [] as NamedSubscriber[];
const newMethodSubscribers = [] as NamedSubscription[];
const generalSubscribers = state.methodSubscribers;
const newGeneralSubscribers = [] as NamedSubscriber[];

const newGeneralSubscribers = [] as NamedSubscription[];
const stagePlanners = state.stagePlanners;
const newStagePlanners = [] as NamedStagePlanner[];
const removeConceptQue = state.removeConceptQue;

methodSubscribers.forEach(named => {
Expand All @@ -25,7 +27,7 @@ export function removeConceptsViaQueReducer(state: AxiumState, _action: Action)
if (!exists) {
newMethodSubscribers.push(named);
} else {
named.subscriber.unsubscribe();
named.subscription.unsubscribe();
}
});

Expand All @@ -39,7 +41,21 @@ export function removeConceptsViaQueReducer(state: AxiumState, _action: Action)
if (!exists) {
newGeneralSubscribers.push(named);
} else {
named.subscriber.unsubscribe();
named.subscription.unsubscribe();
}
});

stagePlanners.forEach(named => {
let exists = false;
removeConceptQue.forEach(concept => {
if (concept.name === named.name) {
exists = true;
}
});
if (!exists) {
newStagePlanners.push(named);
} else {
named.conclude();
}
});

Expand All @@ -48,6 +64,7 @@ export function removeConceptsViaQueReducer(state: AxiumState, _action: Action)
// generation: state.generation + 1,
methodSubscribers: newMethodSubscribers,
generalSubscribers: newGeneralSubscribers,
stagePlanners: newStagePlanners,
removeConceptQue: []
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/concepts/axium/qualities/setBlockingMode.quality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const axiumSetBlockingMode = prepareActionWithPayloadCreator<SetBlockingM

export function setBlockingModeReducer(state: AxiumState, _action: Action) {
let methodSubscribers = state.methodSubscribers;
methodSubscribers.forEach(named => named.subscriber.unsubscribe());
methodSubscribers.forEach(named => named.subscription.unsubscribe());
methodSubscribers = [];

const payload = selectPayload<SetBlockingModePayload>(_action);
Expand All @@ -28,7 +28,7 @@ export function setBlockingModeReducer(state: AxiumState, _action: Action) {
});
methodSubscribers.push({
name: concept.name,
subscriber: sub as Subscriber<Action>
subscription: sub as Subscriber<Action>
});
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/concepts/axium/qualities/setDefaultMode.quality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const axiumSetDefaultMode = prepareActionWithPayloadCreator<SetDefaultMod

export function setDefaultModeReducer(state: AxiumState, _action: Action) {
let methodSubscribers = state.methodSubscribers;
methodSubscribers.forEach(named => named.subscriber.unsubscribe());
methodSubscribers.forEach(named => named.subscription.unsubscribe());
methodSubscribers = [];
const payload = selectPayload<SetDefaultModePayload>(_action);
const concepts = payload.concepts;
Expand All @@ -27,7 +27,7 @@ export function setDefaultModeReducer(state: AxiumState, _action: Action) {
});
methodSubscribers.push({
name: concept.name,
subscriber: sub as Subscriber<Action>
subscription: sub as Subscriber<Action>
});
}
});
Expand Down
20 changes: 4 additions & 16 deletions src/concepts/chain/chain.principle.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
import { Subscriber, Subject } from 'rxjs';
import { Concept } from '../../model/concept';
import { Action, createAction, primeAction } from '../../model/action';
import { PrincipleFunction } from '../../model/principle';
import { Action } from '../../model/action';
import { PrincipleFunction, registerPrincipleSubscription } from '../../model/principle';
import { Chain, chainName } from './chain.concept';
import { selectState } from '../../model/selector';
import { AxiumState } from '../axium/axium.concept';
import {
RegisterSubscriberPayload, axiumRegisterSubscriberType,
} from '../axium/qualities/registerSubscriber.quality';

export const chainPrinciple: PrincipleFunction = (
observer: Subscriber<Action>,
_concepts: Concept[],
concepts$: Subject<Concept[]>,
) => {
// let pass = true;
// setInterval(() => {
// pass = true;
// }, 50);
const subscriber = concepts$.subscribe((concepts: Concept[]) => {
const subscription = concepts$.subscribe((concepts: Concept[]) => {
const chainState = selectState<Chain>(concepts, chainName);
if (chainState.actionQue.length > 0) {
// pass = false;
Expand All @@ -30,10 +23,5 @@ export const chainPrinciple: PrincipleFunction = (
axiumState.action$?.next(nextAction);
}
});
const primedRegisterSubscriber = primeAction(_concepts, createAction(axiumRegisterSubscriberType));
primedRegisterSubscriber.payload = {
subscriber,
name: chainName,
} as RegisterSubscriberPayload;
observer.next(primedRegisterSubscriber);
registerPrincipleSubscription(observer, _concepts, chainName, subscription);
};
Loading

0 comments on commit e4b3b18

Please sign in to comment.