- Extract strategy selection mashinery from
3-function.js
to reuse it for any strategy of certain format:
- Implement
selectStrategy(strategy, name)
returning function - Reading certain behaviour from
strategy
collection do not use technique like thisrenderers[rendererName] || renderers.abstract
- Try to get
strategy
collection keys and check required key; in collection contains no key useabstract
instead
- Rewrite example from
3-function.js
to decouple strategy implementation andconsole
- Resurn
string
from 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
Strategy
class: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>)
createStrategy
will 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