Skip to content

Instantly share code, notes, and snippets.

View dontwork's full-sized avatar

dontwork dontwork

  • Leeds, UK
View GitHub Profile
@barneycarroll
barneycarroll / mSPA.js
Last active December 11, 2016 18:25
A Mithril v1 route plugin for SPAs
var rootProxies = [ [], [] ]
// We apply m.route to a proxy node outside of the document
// This function ensures any given root always returns the same
// proxy.
function getProxy( root ){
var roots = rootProxies[ 0 ]
var proxies = rootProxies[ 1 ]
var index = roots.indexOf( root )
var proxy
@ianmetcalf
ianmetcalf / mithril-debounce.js
Last active February 4, 2016 19:54
Delay redraw for debounced events,based on https://www.npmjs.com/package/debounce
import m from 'mithril';
import now from 'date-now';
export default function debounce(func, wait = 100, immediate = false) {
let context, args, timestamp, timeout, result;
function debounced() {
context = this;
args = arguments;
timestamp = now();
@gilbert
gilbert / example-use.js
Last active August 18, 2016 13:44
Back-button & forward-button compatible Redux-like state management for Mithril.js
var BlogComments = {}
BlogComments.controller = function (options) {
App.state.fetch('blogComments', `/api/blog-post/${ options.blog_id }/comments`)
}
BlogComments.view = function (ctrl, options) {
var comments = App.state.blogComments
return m('.blog-comments-component', [
@StephanHoyer
StephanHoyer / filterinput.js
Created May 20, 2015 10:07
Select2-like mithril input
'use strict';
var m = require('mithril');
var icons = require('client/utils/icons');
var remove = require('lodash/array/remove');
var transform = require('lodash/object/transform');
var last = require('lodash/array/last');
var code = require('yields-keycode');
function sameAs(filterA) {