mirror of
https://github.com/BorysLevytskyi/BitwiseCmd.git
synced 2025-12-23 21:22:48 +01:00
React boilerplate
This commit is contained in:
72
src.old/js_unused/bindr.js
Normal file
72
src.old/js_unused/bindr.js
Normal file
@@ -0,0 +1,72 @@
|
||||
(function(){
|
||||
"use strict";
|
||||
|
||||
var bindr = {};
|
||||
|
||||
bindr.bindChildren = function(container, model) {
|
||||
var elements = container.querySelectorAll('[data-bind]');
|
||||
Array.prototype.call(elements, function(el){
|
||||
});
|
||||
};
|
||||
|
||||
bindr.bind = function(element, model, propertyName) {
|
||||
};
|
||||
|
||||
bindr.attachView = function(viewElement, model) {
|
||||
var elements = viewElement.querySelectorAll('[data-bindr]'),
|
||||
count = elements.length,
|
||||
i =0, el;
|
||||
|
||||
for(;i<count; i++){
|
||||
el = elements[i];
|
||||
this.bindElement(el, model, el.getAttribute('data-bindr'))
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
function bindInput(model, intput, propertyName) {
|
||||
bindTextInput(intput, model, propertyName);
|
||||
}
|
||||
|
||||
function bindCheckBox(element, model, propertyName) {
|
||||
element.checked = model[propertyName];
|
||||
|
||||
element.addEventListener('changed', function (e) {
|
||||
model[propertyName] = e.target.checked == true;
|
||||
});
|
||||
|
||||
model.observe(propertyName, function (property, value) {
|
||||
if (window.event && window.event.target == element) {
|
||||
return;
|
||||
}
|
||||
|
||||
element.checked = value;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function bindTextInput(input, model, propertyName) {
|
||||
input.value = model[propertyName];
|
||||
|
||||
input.addEventListener('keyup', function (e) {
|
||||
model[propertyName] = e.target.value;
|
||||
});
|
||||
|
||||
model.observe(propertyName, function (property, value) {
|
||||
if (window.event && window.event.target == input) {
|
||||
return;
|
||||
}
|
||||
|
||||
input.value = value;
|
||||
});
|
||||
}
|
||||
|
||||
function bindHtmlElement(model, el, propertyName) {
|
||||
model.observe(propertyName, function(propery, value){
|
||||
el.innerHTML = value;
|
||||
});
|
||||
}
|
||||
|
||||
window.core.bindr = bindr;
|
||||
})();
|
||||
57
src.old/js_unused/commandsFeature.js
Normal file
57
src.old/js_unused/commandsFeature.js
Normal file
@@ -0,0 +1,57 @@
|
||||
(function(app, core){
|
||||
"use strict";
|
||||
|
||||
var should = core.should;
|
||||
|
||||
function Command(name) {
|
||||
this.name = name;
|
||||
this.executionHandlers = [];
|
||||
}
|
||||
|
||||
Command.prototype.execute = function (cmdArgs) {
|
||||
cmdArgs = cmdArgs || {};
|
||||
cmdArgs.commandHandled = false;
|
||||
|
||||
for(var i=0; i<this.executionHandlers.length; i++) {
|
||||
this.executionHandlers[i](cmdArgs);
|
||||
if(cmdArgs.commandHandled === true) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Command.prototype.subscribe = function (handler) {
|
||||
this.executionHandlers.push(handler);
|
||||
// TODO: unsubcribe
|
||||
};
|
||||
|
||||
app.commandHandlers = {};
|
||||
|
||||
app.command = function(name, handler) {
|
||||
var cmd = this.commandHandlers[name];
|
||||
|
||||
if(cmd == null) {
|
||||
cmd = this.commandHandlers[name] = new commandr.Command(name);
|
||||
}
|
||||
|
||||
if(typeof handler == "function") {
|
||||
cmd.subscribe(handler);
|
||||
}
|
||||
|
||||
if (typeof handler == "object") {
|
||||
|
||||
if(typeof handler.execute != "function"){
|
||||
console.warn('Given handler is an object, but doesn\'t have "execute" function');
|
||||
return cmd;
|
||||
}
|
||||
|
||||
this.di.resolveProperties(handler);
|
||||
cmd.subscribe(handler.execute.bind(handler));
|
||||
}
|
||||
|
||||
return cmd;
|
||||
};
|
||||
|
||||
window.commandr = commandr;
|
||||
|
||||
})(window.app, window.core);
|
||||
Reference in New Issue
Block a user