Skip to content

Instantly share code, notes, and snippets.

View WreckedAvent's full-sized avatar

Riley Cat WreckedAvent

  • Los Angeles, California
View GitHub Profile
@WreckedAvent
WreckedAvent / mithril user permission switching (es6).js
Last active July 12, 2016 18:17
simple strategy for showing different mithril views based on permissions
// 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
])
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
// 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 {
/// <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[]
}
@WreckedAvent
WreckedAvent / breadcrumbs.js
Last active October 6, 2019 23:38
basic data flow example
import * as m from 'mithril'
// this is a "presentation" component and knows nothing about the world
export const view = (_, { link }) => m('.nav', m('.breadcrumbs', [
m('a', { href: link })
]))
@WreckedAvent
WreckedAvent / child.js
Created August 17, 2016 18:43
code flow.js
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!')
}
}
@WreckedAvent
WreckedAvent / curry.sjs
Last active August 19, 2016 15:33
sweet js ML-style auto-curried function literals
// 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
@WreckedAvent
WreckedAvent / let.sjs
Last active May 29, 2020 07:30
sweet js ML-style let bindings for auto-curried functions
// 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