diff --git a/StagePlanner.md b/StagePlanner.md index 419942e..800a71f 100644 --- a/StagePlanner.md +++ b/StagePlanner.md @@ -120,10 +120,14 @@ const plan = axium.stage('Stage DispatchOptions Test', } ]); ``` -To prevent action overflow, each stage is paying attention to consecutive actions of the same type. In an action overflow state, sequentially the overflow will call the same dispatch before called the next dispatch even if within the same stage. +To prevent action overflow, each stage is paying attention to consecutive actions of the same type. Noting that this can likewise be overwhelmed via a debounce set to 0. If debounce 0 is utilized, the current stage should change. Keep in mind behind the scenes during a STRX runtime, there will be multiple strategies running concurrently. Observe the runCount specified in this example. Please look to the STRX's tests folder. +To save on potential memory bloat we are only keeping track of the most recent valid 5 actions per stage to prevent action overflow. This may change in the future pending some stage that requires a larger bandwidth of actions. Likewise the amount of actions in each stage should be limited regardless. + +Lastly, in an action overflow state, sequentially the overflow will call the same dispatch before calling the next dispatch even if within the same stage. Pay attention to the example above and the final console.log() output. + ## Stage Planner within your Principle STRX is designed to be ran primarily through its loaded concepts and their associated principles. To prevent unexpected behaviors in your own principles. Please utilize the supplied KeyedSelector for axium's open property to begin the stage of your concepts. ```typescript diff --git a/package.json b/package.json index dc29559..200fdae 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@phuire/strx", - "version": "0.0.27", + "version": "0.0.29", "description": "Unified Turing Machine", "main": "dist/index.js", "module": "dist/index.mjs", diff --git a/src/model/stagePlanner.ts b/src/model/stagePlanner.ts index 589f0ed..543f574 100644 --- a/src/model/stagePlanner.ts +++ b/src/model/stagePlanner.ts @@ -147,12 +147,33 @@ const handleStageDelimiter = goodAction = false; } } else if (stageDelimiter) { - stageDelimiter = { - stage: plan.stage, - prevActions: [...stageDelimiter.prevActions, action.type], - unionExpiration: [...stageDelimiter.unionExpiration, action.expiration], - runOnceMap: new Map() - }; + if (stageDelimiter.prevActions.length > 4) { + stageDelimiter = { + stage: plan.stage, + prevActions: [ + stageDelimiter.prevActions[1], + stageDelimiter.prevActions[2], + stageDelimiter.prevActions[3], + stageDelimiter.prevActions[4], + action.type + ], + unionExpiration: [ + stageDelimiter.unionExpiration[1], + stageDelimiter.unionExpiration[2], + stageDelimiter.unionExpiration[3], + stageDelimiter.unionExpiration[4], + action.expiration + ], + runOnceMap: new Map() + }; + } else { + stageDelimiter = { + stage: plan.stage, + prevActions: [...stageDelimiter.prevActions, action.type], + unionExpiration: [...stageDelimiter.unionExpiration, action.expiration], + runOnceMap: new Map() + }; + } } else { stageDelimiter = { stage: plan.stage, @@ -230,6 +251,12 @@ export class UnifiedSubject extends Subject { if (options?.setStage) { plan.stage = options.setStage; } + if (options?.iterateStage || (options?.setStage && options.setStage !== plan.stage)) { + stageDelimiter.prevActions = []; + stageDelimiter.unionExpiration = []; + stageDelimiter.runOnceMap = new Map(); + this.stageDelimiters.set(key, stageDelimiter); + } // Horrifying // Keep in place, this prevents branch prediction from creating ghost actions if there is an action overflow. if (plan.stageFailed === -1) {