This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// utilizes the browser eventsystem | |
// usefull in cases where you need communication between independent components | |
// registered events are automatically removed onunload with preserving any other onunload handler | |
var eventsMixin = function(target) { | |
var _subscriptions = []; | |
target.broadcast = function(type, payload) { | |
var ev = new CustomEvent(type, { | |
detail: payload, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/****************************************** | |
* Firebase mixin | |
******************************************/ | |
export function mixinFirebase(target) { | |
var OBJECT = '[object Object]', ARRAY = '[object Array]', STRING = '[object String]', FUNCTION = '[object Function]'; | |
var type = {}.toString; | |
var _references = []; | |
function unify(key, value) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fireactive = function(controller) { | |
return function(args) { | |
var instance = {}; | |
var _ref = args.firebase; | |
instance.ref = _ref; | |
if (args.asObject) { | |
_ref.on('value', function asObject(snap) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var HTMLTags = ['A', 'DIV', 'SECTION', 'HEADER', 'FOOTER', 'P',....]; | |
m.dom = {}; | |
m.defineDOM = function defineDOM(elementName, component, conf) { | |
// register a html tag, no special component view given | |
if (!component) { | |
elementName = elementName.toLowerCase(); | |
m.dom[elementName] = function(attrs, children) { | |
return m(elementName, attrs, children); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
m.createComponent = function(proto) { | |
function _component(attrs, children) { | |
// always return a fresh instance, allows for call without new | |
if(!(this instanceof _component)) { | |
return new _component(attrs, children); | |
} | |
if(!children && Array.isArray(attrs)) { | |
children = attrs; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/***************************************** | |
/* DOM touch support module | |
/*****************************************/ | |
if (!window.CustomEvent) { | |
window.CustomEvent = function (event, params) { | |
params = params || { bubbles: false, cancelable: false, detail: undefined }; | |
var evt = document.createEvent('CustomEvent'); | |
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail); | |
return evt; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Dinosaurs = { | |
model: function() { | |
// return a firebase reference to our database | |
return new Firebase('https://dinosaur-facts.firebaseio.com'); | |
}, | |
controller: function() { | |
var ref = Dinosaurs.model(); | |
this.facts = mithrilFire(ref.orderByChild('height')); | |
}, | |
view: function(ctrl) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// mithrilFire usage demo | |
// using firebase database "dinosaur-facts" | |
var Dinosaurs = { | |
model: function() { | |
// return a firebase reference to our database | |
return new Firebase('https://dinosaur-facts.firebaseio.com'); | |
}, | |
controller: function() { | |
var data = Dinosaurs.model(); |