JSFiddle - React, Tailwind, and code Playground
by Chase Wilson
HTML
<script src="https://raw.github.com/gist/1350840/Object.merge.js"></script>
<script src="https://raw.github.com/gist/1049896/Extend.js"></script>
<script src="https://raw.github.com/gist/1763600/template.js"></script>
JavaScript
(function (win, document) {
var Block,BlockMethods,key,slice,toString,typeOf,implement,wrap;
slice = Array.prototype.slice;
toString = Object.prototype.toString;
typeOf = function (obj) {
return ({}).toString.call(obj).match(/\s([a-zA-Z]+)/)[1].toLowerCase()
};
implement = function (key, value, retain){
if(typeOf(key) === 'object') {
for( var k in key ) {
implement.call(this,k, key[k]);
}
return;
}
this[key] = (typeof value === 'function') ? (retain) ? value : wrap(this, key, value) : value;
return this;
};
wrap = function (self, key, method){
var wrapper = function(){
var caller = this.caller,
current = this.$caller;
this.caller = current;
this.$caller = wrapper;
var result = method.apply(this, arguments);
this.$caller = current;
this.caller = caller;
return result;
}
wrapper.$parent = self[key];
wrapper.$name = key;
return wrapper;
};
BlockMethods = {
initialize: function (options) {
options = options || {};
var self = this, container = options.container;
if(options.template) {
this.setTemplate(options.template);
}
if(options.container) {
this.setContainer(options.container);
}
}
,setChild: function (key, value) {
this._children[key] = value;
}
,getChild: function (key) {
console.log('got child '+ key);
return this._children[key];
}
,removeChild: function (key) {
return this.removeChildren(key);
}
,setChildren: function (children) {
var key;
for(key in children) {
if(children.hasOwnProperty(key))
this.setChild(key, children[key]);
}
}
/**
* Block#getChildren
*
* getChildren(key [,...]) // { key: `Block` child }
*/
,getChildren:...