(create-registry registry)
Creates a 'Command' registry from a vector of CommandMapSpecs:
Each command specification (CommandMapSpec) should be a map containing at least:
:type
- a unique keyword identifying the command type:recognize-fn
- a function to recognize the command in the instruction map
(fn [element] (and (map? element) (contains? element :your-command-key)):apply
- a function to execute the command:
(fn [instruction command-map-obj command-data] ...):dependencies
- declare way the command should build dependency
{:mode :all-inside} - all commands inside the current map are depednencies
{:mode :none} - no dependencies, the other commands may depend from it.
{:mode :point :point-key :commando/from} - special type of dependency
which declare that current command depends from the command it refer by
exampled :commando/from key.Additional optional keys can include:
:validate-params-fn
- a function to validate command structures, and catch
invalid parameters at the anylisis stage
(fn [command-map-obj] (if valid-params? command-map-obj (throw ...))The function returns a built registry that can be used to resolve Instruction
Example (create-registry [{:type :print :recognize-fn ... :execute-fn ...} commando.commands.builtin/command-fn-spec commando.commands.builtin/command-apply-spec commando.commands.builtin/command-mutation-spec commando.commands.builtin/command-resolve-spec])
Creates a 'Command' registry from a vector of CommandMapSpecs: Each command specification (CommandMapSpec) should be a map containing at least: - `:type` - a unique keyword identifying the command type - `:recognize-fn` - a function to recognize the command in the instruction map (fn [element] (and (map? element) (contains? element :your-command-key)) - `:apply` - a function to execute the command: (fn [instruction command-map-obj command-data] ...) - `:dependencies` - declare way the command should build dependency {:mode :all-inside} - all commands inside the current map are depednencies {:mode :none} - no dependencies, the other commands may depend from it. {:mode :point :point-key :commando/from} - special type of dependency which declare that current command depends from the command it refer by exampled :commando/from key. Additional optional keys can include: - `:validate-params-fn` - a function to validate command structures, and catch invalid parameters at the anylisis stage (fn [command-map-obj] (if valid-params? command-map-obj (throw ...)) The function returns a built registry that can be used to resolve Instruction Example (create-registry [{:type :print :recognize-fn ... :execute-fn ...} commando.commands.builtin/command-fn-spec commando.commands.builtin/command-apply-spec commando.commands.builtin/command-mutation-spec commando.commands.builtin/command-resolve-spec])
cljdoc builds & hosts documentation for Clojure/Script libraries
Ctrl+k | Jump to recent docs |
← | Move to previous article |
→ | Move to next article |
Ctrl+/ | Jump to the search field |