Skip to content

Commit

Permalink
Merge pull request #93 from Phuire-Research/UI
Browse files Browse the repository at this point in the history
UI
  • Loading branch information
REllEK-IO committed Oct 16, 2023
2 parents e3b241f + 0ecc6c1 commit bffbccf
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 12 deletions.
24 changes: 21 additions & 3 deletions ActionStrategy.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ export interface ActionNode {
preposition?: string;
denoter?: string;
}

// Used via the createActionNode function.
export interface ActionNodeOptions {
keyedSelectors?: KeyedSelector[];
semaphore?: [number, number, number, number];
agreement?: number;
decisionNodes?: Record<string, ActionNode>;
decisionNotes?: ActionNotes;
successNode: ActionNode | null;
successNotes?: ActionNotes;
failureNode: ActionNode | null;
failureNotes?: ActionNotes;
lastActionNode?: 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.
Expand Down Expand Up @@ -81,20 +95,24 @@ export interface ActionStrategy {
## Consumer Functions
```typescript
function createStrategy(params: ActionStrategyParameters): ActionStrategy;
function createActionNode(action: Action, options: ActionNodeOptions): ActionNode;
function strategyBegin(strategy: ActionStrategy, data?: unknown): Action;
function strategySuccess(strategy: ActionStrategy, data?: unknown): Action;
function strategyFailed(strategy: ActionStrategy, data?: unknown): Action;
function strategyDecide(strategy: ActionStrategy, decideKey: string, data?: unknown): Action;
function puntStrategy(puntedStrategy: ActionStrategy, newStrategy: ActionStrategy): ActionStrategy;
function strategyPunt(puntedStrategy: ActionStrategy, newStrategy: ActionStrategy): ActionStrategy;
function strategySequence(strategies: ActionStrategy): ActionStrategy | undefined;
```
* createStrategy - Creates a new strategy and returns such to be activated by the strategyBegin consumer function. Data of strategy may be set explicitly.
* createActionNode - Used in conjunction with createStrategy, keep in mind that ActionNodes must be defined in reversed order. As sequentially the only means to add each to either the Success/Failure/Decision nodes is if they are predefined. Creates a new ActionNode that decomposes the supplied Action, this ensures type safety with the action's payload. ActionNodeOptions assigns which ActionNodes will be next within the final ActionStrategy.
* strategyBegin - Returns the initial action of the strategy, updates the ActionList, and creates a union binding between the ActionStrategy and newly created action.
* strategySuccess - Initializes the successNode action, otherwise if null will conclude the Strategy by returning the conclude action. If ActionNode or Strategy's currentNode does not set its preposition, will set such to "Success with"
* strategyFailed - Same as the above, but if the preposition is not set, will set such to "Failed With". And is the default ActionNode called if a lock is dictated while ownership is loaded.
* strategyDecide - Decide key will override or be placed after the preposition if set. And will be used to return the next ActionNode that the key corresponds to. If null, conclude action will be returned.
* puntStrategy - Will return a new strategy with the old strategy within the puntedStrategy Field. That will execute once the new strategy concludes via the consuming functions. That will call strategyBegin on first index of puntedStrategies if present, then remove such from the list, and successNode/decisionNode/failureNode all point to null.
* strategyPunt - Will return a new strategy with the old strategy within the puntedStrategy Field. That will execute once the new strategy concludes via the consuming functions. That will call strategyBegin on first index of puntedStrategies if present, then remove such from the list, and successNode/decisionNode/failureNode all point to null.
* strategySequence - This will take a list of ActionStrategies and return the first strategy with the rest placed in order in the puntedStrategy property. These will fire upon each possible conclusion of the included strategies.

*Note: The data field sets only the data of the strategy, if one wants to edit or set the payload. It should be done explicitly via a type casting. Of the createdAction, or the ActionNode ahead of time.*
*Note: The data field sets only the data of the strategy, if one wants to edit or set the payload. It should be done explicitly the createActionNode function and set by that specific action creator. Do note you may edit the payload once the new ActionNode is created.*
The same is true when accessing the payload from a reducer, method, or principle. As this system is purposefully designed to not function by way of nested types such as:
```
SomethingFactory<AnotherFactor<Factory>>
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.35",
"version": "0.0.36",
"description": "Unified Turing Machine",
"main": "dist/index.js",
"module": "dist/index.mjs",
Expand Down
4 changes: 2 additions & 2 deletions src/concepts/experiment/strategies/puntCounting.strategy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ActionStrategy, ActionStrategyParameters, createActionNode, createStrategy, puntStrategy } from '../../../model/actionStrategy';
import { ActionStrategy, ActionStrategyParameters, createActionNode, createStrategy, strategyPunt } from '../../../model/actionStrategy';
import { counterSelectCount } from '../../counter/counter.selector';
import { experimentCheckInStrategy } from '../qualities/checkInStrategy.quality';
import { experimentCountingStrategy } from './experimentCounting.strategy';
Expand All @@ -16,5 +16,5 @@ export function puntCountingStrategy(): ActionStrategy {
initialNode: stepOne,
};

return puntStrategy(experimentCountingStrategy(), createStrategy(params));
return strategyPunt(experimentCountingStrategy(), createStrategy(params));
}
4 changes: 2 additions & 2 deletions src/concepts/ownership/qualities/backTrack.quality.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Method, MethodCreator, createQuality, defaultMethodCreator, defaultReducer } from '../../../model/concept';
import { Action, ActionType, prepareActionCreator } from '../../../model/action';
import { Subject, map } from 'rxjs';
import { backTrack } from '../../../model/actionStrategy';
import { strategyBackTrack } from '../../../model/actionStrategy';
import { axiumConclude } from '../../axium/qualities/conclude.quality';

export const ownershipBackTrackType: ActionType = 'backtracking to previous ActionNode';
Expand All @@ -12,7 +12,7 @@ const createBackTrackMethodCreator: MethodCreator = () => {
const backTrackMethod: Method = backTrackSubject.pipe(
map((action: Action) => {
if (action.strategy) {
const newAction = backTrack(action.strategy);
const newAction = strategyBackTrack(action.strategy);
return newAction;
}
return axiumConclude();
Expand Down
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ export type {
} from './model/actionStrategy';
export {
createStrategy,
createActionNode,
strategyBegin,
strategySuccess,
strategyFailed,
strategyDecide,
puntStrategy,
createActionNode
strategyPunt,
strategySequence,
strategyBackTrack
} from './model/actionStrategy';
export {
failureConditions,
Expand Down
18 changes: 16 additions & 2 deletions src/model/actionStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ export const strategyDecide = (
return conclude.action;
};
// Remember Water Boy
export const puntStrategy = (
export const strategyPunt = (
puntedStrategy: ActionStrategy,
newStrategy: ActionStrategy,
) => {
Expand All @@ -406,7 +406,21 @@ export const puntStrategy = (
return newStrategy;
};

export const backTrack = (_strategy: ActionStrategy): Action => {
export const strategySequence = (strategies: ActionStrategy[]): ActionStrategy | undefined => {
if (strategies.length > 0) {
const first = strategies[0];
const list = [];
for (let i = 1; i < strategies.length; i++) {
list.push(strategies[i]);
}
first.puntedStrategy = list;
return first;
} else {
return undefined;
}
};

export const strategyBackTrack = (_strategy: ActionStrategy): Action => {
const strategy = _strategy;
if (strategy.currentNode.lastActionNode?.actionType !== nullActionType) {
const newNode = strategy.currentNode.lastActionNode as ActionNode;
Expand Down

0 comments on commit bffbccf

Please sign in to comment.