mirror of
https://github.com/BorysLevytskyi/BitwiseCmd.git
synced 2025-12-23 21:22:48 +01:00
Made observable object sealed after creation
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
(function (core) {
|
(function (core) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
var di = new core.Container();
|
var di = new core.Container();
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ app.run(function() {
|
|||||||
},
|
},
|
||||||
'em': function() {
|
'em': function() {
|
||||||
var cfg = app.get('cmdConfig');
|
var cfg = app.get('cmdConfig');
|
||||||
cfg.emphasizeBytes = !cfg.cmdConfig.emphasizeBytes;
|
cfg.emphasizeBytes = !cfg.emphasizeBytes;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,33 @@
|
|||||||
app.set('is', core.is);
|
app.set('is', core.is);
|
||||||
app.set('should', core.should);
|
app.set('should', core.should);
|
||||||
app.set('bindr', core.bindr);
|
app.set('bindr', core.bindr);
|
||||||
|
|
||||||
|
// Save config in local store
|
||||||
|
app.run(function() {
|
||||||
|
var cfg = app.get('cmdConfig');
|
||||||
|
var storeKey = 'cmdConfig';
|
||||||
|
|
||||||
|
load();
|
||||||
|
|
||||||
|
cfg.observe(function(property, value){
|
||||||
|
save();
|
||||||
|
});
|
||||||
|
|
||||||
|
function save() {
|
||||||
|
localStorage.setItem(storeKey, JSON.stringify(cfg.store()));
|
||||||
|
}
|
||||||
|
|
||||||
|
function load() {
|
||||||
|
var json = localStorage.getItem(storeKey), stored;
|
||||||
|
if(core.is.string(json)) {
|
||||||
|
stored = JSON.parse(json);
|
||||||
|
for(var key in stored) {
|
||||||
|
cfg[key] = stored[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
var template = {
|
var template = {
|
||||||
compile: function (template) {
|
compile: function (template) {
|
||||||
|
|||||||
@@ -38,7 +38,7 @@
|
|||||||
|
|
||||||
this.resolutionStack.unshift(name);
|
this.resolutionStack.unshift(name);
|
||||||
|
|
||||||
console.log('\tresolution path:' + this.resolutionStack.join(' < '));
|
// console.log('\tresolution path:' + this.resolutionStack.join(' < '));
|
||||||
|
|
||||||
var reg = this.store[name];
|
var reg = this.store[name];
|
||||||
if(reg == null) {
|
if(reg == null) {
|
||||||
@@ -51,7 +51,7 @@
|
|||||||
|
|
||||||
this.resolutionStack.shift();
|
this.resolutionStack.shift();
|
||||||
|
|
||||||
console.log('\tresolution path:' + this.resolutionStack.join(' < '));
|
// console.log('\tresolution path:' + this.resolutionStack.join(' < '));
|
||||||
|
|
||||||
return reg.resolved;
|
return reg.resolved;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,13 @@
|
|||||||
var is = core.is;
|
var is = core.is;
|
||||||
|
|
||||||
function ObservableObject () {
|
function ObservableObject () {
|
||||||
this.executionHandlers = [];
|
this.$store = {};
|
||||||
|
this.$executionHandlers = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
ObservableObject.create = function(definition){
|
ObservableObject.create = function(definition){
|
||||||
var obj = new ObservableObject();
|
var obj = new ObservableObject();
|
||||||
|
|
||||||
for(var property in definition){
|
for(var property in definition){
|
||||||
if(!definition.hasOwnProperty(property)){
|
if(!definition.hasOwnProperty(property)){
|
||||||
continue;
|
continue;
|
||||||
@@ -19,18 +21,19 @@
|
|||||||
|
|
||||||
obj[property] = definition[property];
|
obj[property] = definition[property];
|
||||||
}
|
}
|
||||||
return obj;
|
|
||||||
|
return Object.seal(obj);
|
||||||
};
|
};
|
||||||
|
|
||||||
ObservableObject.createGetter = function (propertyName){
|
ObservableObject.createGetter = function (propertyName, store){
|
||||||
return function(){
|
return function(){
|
||||||
return this["_" + propertyName];
|
return this.$store[propertyName];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ObservableObject.createSetter = function(propertyName){
|
ObservableObject.createSetter = function(propertyName, store){
|
||||||
return function(value){
|
return function(value){
|
||||||
this["_" + propertyName] = value;
|
this.$store[propertyName] = value;
|
||||||
this.notifyPropertyChanged(propertyName, value);
|
this.notifyPropertyChanged(propertyName, value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -52,16 +55,25 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var handlers = this.executionHandlers;
|
var handlers = this.$executionHandlers;
|
||||||
var index = handlers.push(func);
|
var index = handlers.push(func);
|
||||||
return function () { handlers.splice(1, index); }
|
return function () { handlers.splice(1, index); }
|
||||||
};
|
};
|
||||||
|
|
||||||
ObservableObject.prototype.notifyPropertyChanged = function(propertyName, value){
|
ObservableObject.prototype.notifyPropertyChanged = function(propertyName, value){
|
||||||
this.executionHandlers.forEach(function(h){
|
this.$executionHandlers.forEach(function(h){
|
||||||
h(propertyName, value);
|
h(propertyName, value);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ObservableObject.prototype.store = function() {
|
||||||
|
return this.$store;
|
||||||
|
};
|
||||||
|
|
||||||
|
ObservableObject.prototype.keys = function() {
|
||||||
|
return Object.keys(this.$store);
|
||||||
|
};
|
||||||
|
|
||||||
core.ObservableObject = ObservableObject;
|
core.ObservableObject = ObservableObject;
|
||||||
|
|
||||||
})(window.core);
|
})(window.core);
|
||||||
Reference in New Issue
Block a user