/*
- *
+ *
* Copyright 2016 RIFT.IO Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Created by onvelocity on 8/23/15.
*/
-import _ from 'lodash'
+import _isArray from 'lodash/isArray'
+import _set from 'lodash/set'
+import _get from 'lodash/get'
import guid from '../guid'
import Position from '../graph/Position'
import IconFactory from './IconFactory'
*/
export default class DescriptorModel {
- constructor(model = {uiState: {}}, parent = null) {
+ constructor(model = {uiState: {}}, parent = null, readonly = false) {
// when our instance has no more strong references
// then our properties will get garbage collected.
this._props_ = new WeakMap();
if (parent instanceof DescriptorModel) {
parent.addChild(this);
}
+ this.isReadOnly = readonly;
}
get fieldNames() {
updateModelList(modelFieldName, modelFieldValue, descriptorClass = DescriptorModel, newItemAddedSuccessCallback = () => {}) {
// value can be Array of (DescriptorModel | json model), DescriptorModel, or json model
- if (_.isArray(modelFieldValue)) {
+ if (_isArray(modelFieldValue)) {
this.model[modelFieldName] = modelFieldValue.map(d => d instanceof descriptorClass ? d.model : d);
return true;
}
return length !== this[propertyName].length;
}
+ setUiState(setting, path, value){
+ _set(this.uiState, [setting].concat(path), value);
+ }
+
+ getUiState(setting, path, defaultValue){
+ return _get(this.uiState, [setting].concat(path), defaultValue);
+ }
+
}