Skip to content

Instantly share code, notes, and snippets.

View Bondifrench's full-sized avatar

Dominik Dumaine Bondifrench

View GitHub Profile
@Bondifrench
Bondifrench / mtabset.js
Created January 30, 2016 20:03
Tabset for Mithril by @JAForbes
var tabset = function tabset(tabnames, active) {
return m("ul", { className: "nav nav-tabs" }, tabnames.map(function (tab) {
return m("li", { role: "presentation", className: tab == active() && "active" }, m("a", { onclick: function onclick() {
return active(tab);
} }, tab));
}));
};
@Bondifrench
Bondifrench / pageslider-mithril.js
Last active August 29, 2015 14:27
Attempt to port React-page slider to Mithril
// React version is here: https://github.com/ccoenraets/react-employee-directory/blob/master/iteration8/js/pageslider-react.js
var PageSlider = {
controller: function(args) {
var ctrl = this;
ctrl.history = m.prop([]);
ctrl.pages = m.prop([]);
ctrl.animating = m.prop(false);
ctrl.slidePage = function(page) {
var history = ctrl.history();
var pages = ctrl.pages();
@Bondifrench
Bondifrench / pubsub.js
Created July 9, 2015 03:15
Pub/Sub, Observer pattern with Mithril/Javascript
https://jsfiddle.net/3p90n4mn/2/
https://github.com/jasonmayes/mdl-component-design-pattern
https://github.com/Satyam/malt
https://github.com/dvcolgan/superflux
http://mithril.js.org/components.html#the-observer-pattern
@Bondifrench
Bondifrench / example.js
Last active August 29, 2015 14:24
Retrieving an array in Mithril
var Ids = [139502, 92769, 57443];
forecasts.model2 = function(Ids) {
console.log(Ids);
return m.request({
method: 'GET',
url: window.location.origin + '/api/',
data: {
reportIds: Ids
}
@Bondifrench
Bondifrench / test.js
Last active August 29, 2015 14:23
Problem with m.request and background
/**
* This version works
**/
var dashboard = {};
dashboard.model = function(id) {
return m.request({
method: 'GET',
url: window.location.origin + '/example/' + id,
})
@Bondifrench
Bondifrench / mexample.js
Created May 17, 2015 13:44
Mithril example with control access for specific route - from Barney Carroll
m.route( document.body, "/dashboard/johndoe", {
"/dashboard/:userID": {
controller : function(){
return m.request( {
url : "/permissions/" + m.route.param( "userID" ),
deserialize : function( xml ){
return new DOMParser().parseFromString( xml, "text/xml" );
}
} ).then(
function success(){},
@Bondifrench
Bondifrench / Mithril.sublime-completions
Created April 30, 2015 00:20
Mithril Sublime Text shortcuts
{
"scope": "source.js",
"completions":
[
{"trigger": "m\tm() Mithril", "contents": "m('${1:div}',{\n\t${2:style: { \\}}, \n\t${3:config: 'function name'}\n\t},[\n\t\t${4:'Children'}\n\t])"},
{"trigger": "mi\tinput Mithril", "contents": "m('input${1:[type=]}', ${2:oninput:}, value: $3)"},
{"trigger": "ma\tlink Mithril", "contents": "m('a[href=${1:/myroute}]', {config: ${2:m.route}}, ${3:'Myroute'})"},
{"trigger": "mm\tmodule Mithril", "contents": "var mymodule = {};\n\nmymodule.vm = ${1:'Object literal \\{\\} or function Constructor'}\n\nmymodule.controller = function (options) {\n\t${2:mymodule.vm.init();}\n};\n\nmymodule.view = function (ctrl) {\n\treturn ${3:'view here'};\n}\nm.module(document${4:.body}, mymodule);"},
{"trigger": "mp\tgetter/setter Mithril", "contents" : "m.prop(${1:'initial value'});"},
{"trigger": "mw\tevent handler Mithril", "contents": "m.withAttr(${1:'string here'}, ${2:callback here})"},
@Bondifrench
Bondifrench / recursion.js
Created June 5, 2014 00:56
Recursion using a loop and without
for (var i=0; i<num; i ++) {
operation();
}
//Equivalent to
if (num <= 0) {return;} //or just return see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return
operation()
return repeat(operation, --num)
@Bondifrench
Bondifrench / forEach.js
Created June 4, 2014 11:06
forEach function in Javascript
for (var i=0;i<list.length;i++) {
console.log(list[i]);
}
//Equivalent to:
//list.forEach(function (i) {
//console.log(i)
//})
@Bondifrench
Bondifrench / filter.js
Created June 4, 2014 11:05
Filter function in Javascript
var bracket = [];
for (var d=0; d<list.length;d++){
if (path.extname(list[d]) === ".".concat(ext)) {
bracket.push(list[d]);
}
}
//bracket = list.filter(function (d) {
// return path.extname(d) === ".".concat(ext);
//});