This file contains 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
// Auto curried function definitions using let, like ML | |
// | |
// Examples: | |
// let add x y = x + y | |
// let map f ctx = tx.map(f) | |
// NOTE: requires auto-curried function macro: https://gist.github.com/WreckedAvent/9aa698d3e9e6a46c5c62c1e266c95f20 | |
syntax let = ctx => { | |
const ids = [] | |
let ret = null | |
let body = null |
This file contains 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
// Auto-curried fun macro, inspired by ML syntax | |
// | |
// Examples: | |
// let add = fun x y { x + y } | |
// let map = fun f x { x.map(f) } | |
syntax fun = ctx => { | |
const ids = [] | |
let ret = null | |
// start parsing our context |
This file contains 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
import * as m from 'mithril' | |
export const controller = function(props) { | |
var self = this | |
this.myAction = msg => { | |
event.preventDefault() | |
// HERE I WANT TO SEND THE 'smg' TO THE 'ctrl.message' ON MainComponent. | |
props.message('set to whatever!') | |
} | |
} |
This file contains 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
/// <reference path="../../mithril.d.ts"/> | |
module Components { | |
interface ViewArgs { | |
sortBy?: any | |
getTracks?: (sort: string) => Model.Track[] | |
selectTrack?: (track: {}) => void | |
isSortedOn?: (sort: string) => string | |
tracks?: Model.Track[] | |
} |
This file contains 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
// based on https://github.com/dontwork/mithril-select/blob/master/src/components/selectOption.js | |
import * as m from 'mithril' | |
import * as isSelected from '../functions/isSelected' | |
const action = (option, selection, e) => { | |
if (isSelected(option, selection)) { | |
const i = selection.indexOf(option) | |
selection.splice(i, 1) | |
} else { |
This file contains 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
import * as m from 'mithril' | |
import * as ko from 'knockout' | |
// both mithril and knockout have a concept of 'observables' | |
// mithril calls this a 'prop' for some reason or another | |
var mObs = m.prop() | |
var kObs = ko.observable() | |
// observables have a fairly simple operation - call it with nothing | |
// to get the current state, call it with something to set the state |
This file contains 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
// some service to get the user's permissions | |
import * as user from './user-service' | |
import * as m from 'mithril' | |
const adminView = (ctrl) => m('.container.admin', [ | |
m('h1', 'Hello admin') | |
// show admin specific controls | |
]) |