-
-
Save futurist/c6b1534aaa048533c16d to your computer and use it in GitHub Desktop.
JS Bin j2c mithril demo // source http://jsbin.com/qoxaze
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="description" content="j2c mithril demo"> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
<script src="https://rawgit.com/lhorie/mithril.js/next/mithril.min.js"></script> | |
<script src="https://rawgit.com/pygy/j2c/next/dist/j2c.global.js"></script> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
//- lib ------------------- | |
var styles = ''; | |
var liveStyles = ''; | |
var styler = { | |
liveUpdate: function(style) { | |
var scopedStyle = j2c.sheet(style); | |
liveStyles += scopedStyle; | |
return scopedStyle; | |
}, | |
attach: function(style) { | |
var scopedStyle = j2c.sheet(style); | |
console.log("scopedStyle", scopedStyle) | |
styles += scopedStyle; | |
return scopedStyle; | |
}, | |
view: function() { | |
var el = [m('style', styles),m('style', liveStyles)]; | |
liveStyles = ''; | |
return el; | |
} | |
}; | |
//- some module ------------------- | |
var cls = styler.attach({ | |
'.foo': { | |
background: 'blue' | |
}, | |
}); | |
console.log('cls',cls) | |
var d=styler.attach({ | |
".bar":{ | |
color:'red' | |
} | |
}); | |
console.log('d', d, 1234, styles) | |
function someRandomView() { | |
return m('span.' + cls.foo, 'Some random content'); | |
} | |
function someDynamiclyStlyedView(scope) { | |
var cls = styler.liveUpdate({ | |
'.bar': { background: scope.background } | |
}); | |
return m('span.' + cls.bar, 'Some blinky stuff content'); | |
} | |
//- main view ------------------- | |
m.mount(document, { | |
controller: function() { | |
var scope = { | |
background: 'red' | |
}; | |
setInterval(function() { | |
scope.background = scope.background === 'red' ? 'green' : 'red'; | |
m.redraw(); | |
}, 100010); | |
return scope; | |
}, | |
view: function(scope) { | |
return [ | |
someRandomView(), | |
someDynamiclyStlyedView(scope), | |
styler.view() | |
]; | |
} | |
}); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">//- lib ------------------- | |
var styles = ''; | |
var liveStyles = ''; | |
var styler = { | |
liveUpdate: function(style) { | |
var scopedStyle = j2c.sheet(style); | |
liveStyles += scopedStyle; | |
return scopedStyle; | |
}, | |
attach: function(style) { | |
var scopedStyle = j2c.sheet(style); | |
console.log("scopedStyle", scopedStyle) | |
styles += scopedStyle; | |
return scopedStyle; | |
}, | |
view: function() { | |
var el = [m('style', styles),m('style', liveStyles)]; | |
liveStyles = ''; | |
return el; | |
} | |
}; | |
//- some module ------------------- | |
var cls = styler.attach({ | |
'.foo': { | |
background: 'blue' | |
}, | |
}); | |
console.log('cls',cls) | |
var d=styler.attach({ | |
".bar":{ | |
color:'red' | |
} | |
}); | |
console.log('d', d, 1234, styles) | |
function someRandomView() { | |
return m('span.' + cls.foo, 'Some random content'); | |
} | |
function someDynamiclyStlyedView(scope) { | |
var cls = styler.liveUpdate({ | |
'.bar': { background: scope.background } | |
}); | |
return m('span.' + cls.bar, 'Some blinky stuff content'); | |
} | |
//- main view ------------------- | |
m.mount(document, { | |
controller: function() { | |
var scope = { | |
background: 'red' | |
}; | |
setInterval(function() { | |
scope.background = scope.background === 'red' ? 'green' : 'red'; | |
m.redraw(); | |
}, 100010); | |
return scope; | |
}, | |
view: function(scope) { | |
return [ | |
someRandomView(), | |
someDynamiclyStlyedView(scope), | |
styler.view() | |
]; | |
} | |
});</script></body> | |
</html> |
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
//- lib ------------------- | |
var styles = ''; | |
var liveStyles = ''; | |
var styler = { | |
liveUpdate: function(style) { | |
var scopedStyle = j2c.sheet(style); | |
liveStyles += scopedStyle; | |
return scopedStyle; | |
}, | |
attach: function(style) { | |
var scopedStyle = j2c.sheet(style); | |
console.log("scopedStyle", scopedStyle) | |
styles += scopedStyle; | |
return scopedStyle; | |
}, | |
view: function() { | |
var el = [m('style', styles),m('style', liveStyles)]; | |
liveStyles = ''; | |
return el; | |
} | |
}; | |
//- some module ------------------- | |
var cls = styler.attach({ | |
'.foo': { | |
background: 'blue' | |
}, | |
}); | |
console.log('cls',cls) | |
var d=styler.attach({ | |
".bar":{ | |
color:'red' | |
} | |
}); | |
console.log('d', d, 1234, styles) | |
function someRandomView() { | |
return m('span.' + cls.foo, 'Some random content'); | |
} | |
function someDynamiclyStlyedView(scope) { | |
var cls = styler.liveUpdate({ | |
'.bar': { background: scope.background } | |
}); | |
return m('span.' + cls.bar, 'Some blinky stuff content'); | |
} | |
//- main view ------------------- | |
m.mount(document, { | |
controller: function() { | |
var scope = { | |
background: 'red' | |
}; | |
setInterval(function() { | |
scope.background = scope.background === 'red' ? 'green' : 'red'; | |
m.redraw(); | |
}, 100010); | |
return scope; | |
}, | |
view: function(scope) { | |
return [ | |
someRandomView(), | |
someDynamiclyStlyedView(scope), | |
styler.view() | |
]; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment