Skip to content

Instantly share code, notes, and snippets.

View Bondifrench's full-sized avatar

Dominik Dumaine Bondifrench

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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 / mcheckbox.js
Created January 30, 2016 20:05
A checkbox for Mithril by @JAForbes
var checkbox = function checkbox(label, prop) {
return m("label.checkbox-inline", m("input[type=checkbox]", {
checked: prop(),
onclick: m.withAttr("checked", prop)
}), _.capitalize(label));
};
@Bondifrench
Bondifrench / mselect.js
Created January 30, 2016 20:07
A select element for Mithril from @JAForbes
var select = function select(options, prop, attr) {
if (typeof prop() == "undefined" || prop() == "") {
prop(options[0]);
}
if (options.length == 0) {
prop("");
}
return m("select.form-control", _.extend({
@Bondifrench
Bondifrench / mautocomplete.js
Last active March 7, 2016 09:05
A mithril autocomplete component using Horsey by @JAForbes
var pluck = require("lodash").pluck;
var groupBy = require("lodash").groupBy;
var forceRender = require("lodash").identity;
var m = require("mithril");
var horsey = require("horsey");
var controller = function controller(label, data, property) {
//split the data set into subsets for performance