import debug from 'debug'
var log = debug('facond.rule')
/**
* Rules bind :js:class:`Action`
*/
class Rule {
/**
* Instanciate a Rule with a field name and a list of actions.
*
* @param {field} Field name as a string, with the form prefix.
* @param {actions} List of actions for this rule.
*/
constructor(field, actions) {
this.field = field
this.actions = actions
}
// Execute all actions of this rule.
apply(form) {
log('[Rule]', this, '.apply(', form, ')')
for (var i=0; i<this.actions.length; i++) {
this.actions[i].execute(form.field(this.field))
}
}
}
export {
Rule,
}
|