Shreyas arya

Generation

generate functionTue, 24 Jan 2023

We need to create validators for each status. The validator will check if transition from current state is allowed or not.

Script var todo = { status: 'open', validators: { 'open': ['close'], 'close': ['open'], 'assigned': ['open', 'close'] }, init: function(status) { this.status = status; return this; }, change: function(newStatus) { if (this.validators[this.status].indexOf(newStatus) > -1) { this.status = newStatus; return this; } else { return 'Error'; } } }

Questions about programming?Chat with your personal AI assistant