Challenge Engine
This provides a challenge definition system that allows developers to define challenges as a series of steps and validations for their own product.
Challenges
A challenge is a series of steps containing a validation definition that will, upon reception of an event move to the next step or not depending on the validation and the details of that event.
Example:
If the event button-click
is triggered, the challenge will move on to the next step
Each step can also contain custom data with a key and a value. The key can be used to define a behavior specific to this step
API
Kano.Challenge.Definition
A challenge needs to have its steps behaviors and shorthands defined before the steps are processed, this is why, the steps are only expanded when the challenge starts
Definition#start
Expand the steps, start the challenge with the first step. Before starting, the challenge is in an idle state.
Definition#nextStep
Moves to the next step.
Definition#defineBehavior
Defines a callback that will run every time a custom property in a step changes. This can be used to display UI hints to the user.
def;
Definition#defineShorthand
Some parts of the challenges will be very similar, you can define shorthands for groups of steps in your challenges that will be expanded by the engine before running the challenge.
// This would define a shortcut with static validations but flexible copiesdef;
Definition#triggerEvent
Notifies the engine of an event. This will make the engine checks for the current validation
def;
Definition#addValidation
Adds a validation for a specific event. When this event is triggered, the engine will run the function to know if the event matches the validation.
def;
Definition#addMatchFallback
If the event was triggered, but didn't pass the validation, the match fallback will run. This allows you to define UI actions to help the user get back on track if needed
def;
Definition#addOppositeAction
When waiting for an event, but a different one is triggered some actions can be performed using addOppositeAction
def;
Definition#addToStore
Adds data to a store, use this to create handles to runtime data of your projects that needs to be accessed later on.
def;
Definition#getFromStore
Retrieves the data stored earlier.
def;
Kano.Challenge.ElementsRegistry
ElementsRegistry#add
Adds an element to the regitry with an id.
// This would make the element available globally from the id `next-button`reg;
ElementsRegistry#get
Get an element from the regitry.
// In a step behavior for exampledef;
API style
// Can extend class for challenge abstraction and resusability// Here we only define behaviors and validations spcific to blockly challenges { super; thisreg = elementsRegistry this; } // ... // A Kano Code challenge would be an extension of a blockly challenge as it also contains its own UI { superelementsRegistry; thisbeacon = document; this; }