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

Dx #199

Merged
merged 3 commits into from
Apr 24, 2024
Merged

Dx #199

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
37 changes: 15 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -150,7 +152,7 @@ import {
MethodCreator,
Action,
prepareActionCreator,
createQuality,
createQualitySetWithPayload,
UnifiedSubject,
createMethodWithState,
strategySuccess,
Expand All @@ -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<Concepts>, semaphore?: number) =>
export type uXqOfUxField = {
state: UXState
};

// [ActionCreator/ActionCreatorWithPayload, ActionType, Quality]
export const [uXqOfUX, uXqOfUXType, uXqOfUXQuality] = createQualitySetWithPayload<uXqOfUxField>({
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<Concepts>, semaphore?: number) =>
// Only if you need to access state, otherwise
createMethodWithState<UXState>((action, state) => {
if (action.strategy) {
Expand All @@ -186,24 +190,13 @@ const uXqOfUXCreator: MethodCreator = (concepts$?: Subject<Concepts>, 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
// );
```
Expand Down
4 changes: 2 additions & 2 deletions SpatialOwnership.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
55 changes: 12 additions & 43 deletions src/concepts/axium/qualities/addConceptsFromQue.quality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Action>) => {
// 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<Action>;
// blockingMethodSubscription(action$, act);
// }) as Subscriber<Action>;
// 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
});
/*#>*/
48 changes: 23 additions & 25 deletions src/concepts/axium/qualities/appendActionListToDialog.quality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>;
strategyTopic: string;
strategyData: unknown;
}
export const axiumAppendActionListToDialogType: ActionType = 'append Action List to Axium\'s Dialog';
export const axiumAppendActionListToDialog =
prepareActionWithPayloadCreator<AppendActionListToDialogPayload>(axiumAppendActionListToDialogType);

export function axiumAppendActionListToDialogReducer(state: AxiumState, action: Action): AxiumState {
const payload = selectPayload<AppendActionListToDialogPayload>(action);
let newDialog = '';
if (state.storeDialog) {
payload.actionList.forEach(str => {newDialog += str + ' ';});
if (state.logging) {
console.log(newDialog);
export const [
axiumAppendActionListToDialog,
axiumAppendActionListToDialogType,
axiumAppendActionListToDialogQuality
] = createQualitySetWithPayload<AppendActionListToDialogPayload>({
type: 'append Action List to Axium\'s Dialog',
reducer: (state: AxiumState, action) => {
const payload = selectPayload<AppendActionListToDialogPayload>(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,
);
});
/*#>*/
38 changes: 18 additions & 20 deletions src/concepts/axium/qualities/appendConceptsToAddQue.quality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<AxiumAppendConceptsToAddQuePayload>(axiumAppendConceptsToAddQueType);

export function axiumAppendConceptsToAddQueReducer(state: AxiumState, action: Action) {
const payload = selectPayload<AxiumAppendConceptsToAddQuePayload>(action);
const addConceptQue = [
...payload.concepts
];
return {
...state,
addConceptQue,
};
}

export const axiumAppendConceptsToAddQueQuality = createQuality(
export const [
axiumAppendConceptsToAddQue,
axiumAppendConceptsToAddQueType,
axiumAppendConceptsToAddQueReducer,
defaultMethodCreator
);
axiumAppendConceptsToAddQueQuality
] = createQualitySetWithPayload<AxiumAppendConceptsToAddQuePayload>({
type: 'append Concepts to Axium\'s Add Concept Que',
reducer: (state: AxiumState, action) => {
const payload = selectPayload<AxiumAppendConceptsToAddQuePayload>(action);
const addConceptQue = [
...payload.concepts
];
return {
...state,
addConceptQue,
};
},
methodCreator: defaultMethodCreator
});
/*#>*/
42 changes: 20 additions & 22 deletions src/concepts/axium/qualities/appendConceptsToRemoveQue.quality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<AxiumAppendConceptsToRemoveQuePayload>(axiumAppendConceptsToRemoveQueType);

export function axiumAppendConceptsToRemoveQueReducer(state: AxiumState, action: Action) {
const payload = selectPayload<AxiumAppendConceptsToRemoveQuePayload>(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<AxiumAppendConceptsToRemoveQuePayload>({
type: 'append Concepts to Axium\'s Remove Concept Que',
reducer: (state: AxiumState, action) => {
const payload = selectPayload<AxiumAppendConceptsToRemoveQuePayload>(action);
let removeQue = state.removeConceptQue;
removeQue = [
...removeQue,
...payload.concepts
];
return {
...state,
removeConceptQue: removeQue
};
},
methodCreator: defaultMethodCreator
});
/*#>*/
41 changes: 20 additions & 21 deletions src/concepts/axium/qualities/badAction.quality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<AxiumBadActionPayload>(axiumBadActionType);

export function axiumBadActionReducer(state: AxiumState, action: Action) {
const payload = selectPayload<AxiumBadActionPayload>(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<AxiumBadActionPayload>({
type: 'Axium received a Bad Action',
reducer: (state: AxiumState, action) => {
const payload = selectPayload<AxiumBadActionPayload>(action).badActions;
if (state.logging) {
console.log('Axium Received a Bad Action: ', action);
}
return {
...state,
badActions: [
...state.badActions, ...payload
]
};
}
});
/*#>*/
Loading
Loading