debian-mirror-gitlab/app/assets/javascripts/issue_show/stores/index.js

37 lines
908 B
JavaScript
Raw Normal View History

2019-03-02 22:35:43 +05:30
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
2017-09-10 17:25:29 +05:30
export default class Store {
constructor(initialState) {
this.state = initialState;
this.formState = {
title: '',
description: '',
lockedWarningVisible: false,
updateLoading: false,
2019-03-02 22:35:43 +05:30
lock_version: 0,
2017-09-10 17:25:29 +05:30
};
}
updateState(data) {
if (this.stateShouldUpdate(data)) {
this.formState.lockedWarningVisible = true;
}
2019-03-02 22:35:43 +05:30
Object.assign(this.state, convertObjectPropsToCamelCase(data));
2017-09-10 17:25:29 +05:30
this.state.titleHtml = data.title;
this.state.descriptionHtml = data.description;
2019-03-02 22:35:43 +05:30
this.state.lock_version = data.lock_version;
2017-09-10 17:25:29 +05:30
}
stateShouldUpdate(data) {
2018-12-13 13:39:08 +05:30
return (
this.state.titleText !== data.title_text ||
this.state.descriptionText !== data.description_text
);
2017-09-10 17:25:29 +05:30
}
setFormState(state) {
this.formState = Object.assign(this.formState, state);
}
}