Skip to content

Instantly share code, notes, and snippets.

View spion's full-sized avatar
:shipit:

Gorgi Kosev spion

:shipit:
View GitHub Profile
;;; spion-purescript --- Purescript support for emacs
;;; Commentary:
;;; Code:
(define-derived-mode purescript-mode haskell-mode "PureScript"
"Major mode for PureScript")
(add-to-list 'auto-mode-alist (cons "\\.purs\\'" 'purescript-mode))
import qualified Data.Map.Strict as M
data Node = Text String | Element (M.Map String AttributeValue)
data AttributeValue = Value String | Content [Node]
extractContent :: Node -> [String]
extractContent (Text s) = [s]
extractContent (Element e) =
case M.lookup "content" e of
Just (Content list) -> list >>= extractContent
this.create
.map(title => todos => todos.concat({id: uuid(), title: title, completed: false })
.subscribe(updates);

--

var Timer = process.binding('timer_wrap').Timer;
function test(r) {
return function() {
console.log(r, Timer.now());
}
}
function run() {
@spion
spion / $.js
Last active August 29, 2015 14:05
var $ = React.DOM;
var HelloMessage = React.createClass({displayName: 'HelloMessage',
render: function() {
return $.div({class: "main"},
$.p(null, "Hello"),
$.ul(null,
$.li(null, "First item")),
$.p(null, "Bye bye"))
}
@spion
spion / tc.js
Last active August 29, 2015 14:06
var TC = {};
TC.type = function(typestr) {
return function(msg) {
return function(p, key) {
if (typeof(p) !== typestr)
throw new TypeError(makeMessage(key, msg || 'must be of type ' + typestr));
}
}
}
@spion
spion / assets.md
Last active August 29, 2015 14:06

#v1

Assuming

Promise.promisifyAll(asset.__proto__);
Promise.promisifyAll(permission.__proto__);

The first thing that caught my eye was

mercury.app(document.body, clickCount, render)

I immediately wanted to know the types of all 3 arguments. Obviously, render is a function that produces a virtual dom description, but it wasn't immediately clear what is clickCount - apparently its an observable application state whose value will be passed to the render function when a change is observed.

A more detailed discussion of the events part would be useful - it seems to be the least straightforward part. Its not clear what transformations are applied by mercury.xxxEvent and mercury.event to the function nor what the return type is. Its was also not clear to me if its possible to use valueEvent to observe the value of another component - e.g. to observe the value of a text field when a "Search" button is pressed - or would I need to combine click with change valueEvents (and how to do that - FRP style perhaps?).

//--------------------------
// Observable <-> SVG mappers
//--------------------------
let toWire = element => bool => {
element.attr('stroke', bool ? '#259B24' : '#212121');
element.attr('stroke-width', bool ? "3" : '2');
}
let toWires = elements => bool =>