2017-05-10 07:29:33 -04:00
|
|
|
export default class Store {
|
2017-06-20 05:56:18 -04:00
|
|
|
constructor(initialState) {
|
|
|
|
this.state = initialState;
|
2017-05-12 07:54:10 -04:00
|
|
|
this.formState = {
|
|
|
|
title: '',
|
2017-05-12 10:52:45 -04:00
|
|
|
description: '',
|
2017-05-18 11:51:51 -04:00
|
|
|
lockedWarningVisible: false,
|
2017-05-26 04:29:06 -04:00
|
|
|
updateLoading: false,
|
2017-05-12 07:54:10 -04:00
|
|
|
};
|
2017-05-10 07:29:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
updateState(data) {
|
2017-06-21 20:34:15 -04:00
|
|
|
if (this.stateShouldUpdate(data)) {
|
|
|
|
this.formState.lockedWarningVisible = true;
|
|
|
|
}
|
|
|
|
|
2017-05-10 07:29:33 -04:00
|
|
|
this.state.titleHtml = data.title;
|
|
|
|
this.state.titleText = data.title_text;
|
|
|
|
this.state.descriptionHtml = data.description;
|
|
|
|
this.state.descriptionText = data.description_text;
|
|
|
|
this.state.taskStatus = data.task_status;
|
|
|
|
this.state.updatedAt = data.updated_at;
|
2017-05-18 08:24:34 -04:00
|
|
|
this.state.updatedByName = data.updated_by_name;
|
|
|
|
this.state.updatedByPath = data.updated_by_path;
|
2017-05-10 07:29:33 -04:00
|
|
|
}
|
2017-05-18 11:51:51 -04:00
|
|
|
|
|
|
|
stateShouldUpdate(data) {
|
2017-06-21 20:34:15 -04:00
|
|
|
return this.state.titleText !== data.title_text ||
|
|
|
|
this.state.descriptionText !== data.description_text;
|
2017-05-18 11:51:51 -04:00
|
|
|
}
|
2017-05-30 06:58:50 -04:00
|
|
|
|
|
|
|
setFormState(state) {
|
|
|
|
this.formState = Object.assign(this.formState, state);
|
|
|
|
}
|
2017-05-10 07:29:33 -04:00
|
|
|
}
|