Skip to content

Instantly share code, notes, and snippets.

@nomanHasan
Created March 10, 2018 14:23
Show Gist options
  • Save nomanHasan/9d247abeb22f79fff2b61f59001254b3 to your computer and use it in GitHub Desktop.
Save nomanHasan/9d247abeb22f79fff2b61f59001254b3 to your computer and use it in GitHub Desktop.
class Action {
constructor(type = '', model = '') {
this.type = ` ${type.toUpperCase().replace(' ', '_')}_`;
this.model = model;
this.modelString = `[${model}]`;
this.upperModel = this.model.toUpperCase();
this.request = this.modelString +
this.type +this.model.toUpperCase();
this.success = this.modelString +
this.type +this.model.toUpperCase()+'_SUCCESS';
this.failure = this.modelString +
this.type +this.model.toUpperCase() + '_FAILURE';
}
}
class ModelAction {
constructor(model) {
this.model = model;
this.create = new Action('create', this.model);
this.read = new Action('get', this.model);
this.update = new Action('update', this.model);
this.remove = new Action('remove', this.model);
}
}
class CustomModelAction extends ModelAction{
constructor(model) {
super(model);
this.startEdit = new Action('start edit', this.model);
}
}
const actions = [new ModelAction('Todo'), new ModelAction('Song'), new ModelAction('Event'), new CustomModelAction('User') ];
console.log(actions);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment