- Extract strategy selection mashinery from
3-function.jsto reuse it for any strategy of certain format:
- Implement
selectStrategy(strategy, name)returning function - Reading certain behaviour from
strategycollection do not use technique like thisrenderers[rendererName] || renderers.abstract - Try to get
strategycollection keys and check required key; in collection contains no key useabstractinstead
- Rewrite example from
3-function.jsto decouple strategy implementation andconsole
- Resurn
stringfrom all strategy implementations - Here is an example:
console.log(png(persons))
- Make high level abstraction from
5-agent.js:
- Now we have
registerAgent(name, behaviour)andgetAgent(name, action) - Create
Strategyclass:constructor(strategyName: string, actions: Array<string>)registerBehaviour(implementationName, behaviour)getBehaviour(implementationName, actionName)
- Prepare ESM or CJS module for
Strategy
- Add .d.ts typings
- Add tests and cases
- Rewrite strategy from classes to just module exporting interface:
createStrategy(strategyName: string, actions: Array<string>)createStrategywill return{ registerBehaviour, getBehaviour }without class syntax- Module contains a collection of strategies
- Strategy (closure) contains a collection of
implementations - Implementations (struct) contains a collection of
actions