Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
160 additions
and
156 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
var MouseClicks = require("../../input").MouseClicks | ||
var foldp = require("../../signal/foldp") | ||
var map = require("../../signal/map") | ||
var foldp = require("../../signal").foldp | ||
var transform = require("../../signal").transform | ||
var plainText = require("../../element").plainText | ||
var render = require("../../render") | ||
|
||
var clicks = foldp(MouseClicks(), function (count) { | ||
return count + 1 | ||
}, 0) | ||
|
||
var main = map(clicks, plainText) | ||
var main = transform(clicks, plainText) | ||
|
||
render(main, false) | ||
// => |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
var image = require("../../element").image | ||
var map = require("../../signal/map") | ||
var transform = require("../../signal").transform | ||
var inspect = require("../../signal").inspect | ||
var MousePosition = require("../../input").MousePosition | ||
var render = require("../../render") | ||
|
||
var input = MousePosition() | ||
input | ||
// => | ||
inspect(input) // => | ||
|
||
var edgeLength = map(input, function (pos) { | ||
// application state | ||
var edgeLength = transform(input, function (pos) { | ||
return Math.max(100, Math.max(pos.x, pos.y)) | ||
}) | ||
edgeLength // application state | ||
// => | ||
inspect(edgeLength) // => | ||
|
||
var main = map(edgeLength, function resizableYogi(edgeLength) { | ||
// application view | ||
var main = transform(edgeLength, function resizableYogi(edgeLength) { | ||
return image(edgeLength, edgeLength, "http://elm-lang.org/yogi.jpg") | ||
}) // application view | ||
}) | ||
|
||
render(main, false) | ||
// => | ||
render(main, false) // => |
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
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
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
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,38 @@ | ||
var reductions = require("reducers/reductions") | ||
var concat = require("reducers/concat") | ||
var observable = require("observable") | ||
|
||
// Signal A -> (B -> A -> B) -> B -> Signal B | ||
module.exports = foldp | ||
|
||
function foldp(input, folder, initial) { | ||
return concat(initial, reductions(input, folder, initial)) | ||
function foldp(inputSignal, folder, initialValue) { | ||
var state = initialValue | ||
var listeners = [] | ||
var started = false | ||
|
||
return outputSignal | ||
|
||
function outputSignal(listener) { | ||
if (isGet(listener)) { | ||
return state | ||
} else if (isSet(listener)) { | ||
throw new Error("read-only") | ||
} else { | ||
listeners.push(listener) | ||
if (!started) { | ||
started = true | ||
start() | ||
} | ||
} | ||
} | ||
|
||
function start() { | ||
inputSignal(function onchange(value) { | ||
state = folder(state, value) | ||
listeners.forEach(function (cb) { | ||
cb(state) | ||
}) | ||
}) | ||
} | ||
} | ||
|
||
function isGet(x) { return x === undefined } | ||
function isSet(x) { return typeof x !== "function" } |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
module.exports = { | ||
map: require("./map") | ||
transform: require("./transform") | ||
, foldp: require("./foldp") | ||
, mapMany: require("./mapMany") | ||
, transformMany: require("./transformMany") | ||
, inspect: require("./inspect") | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
var document = require("global/document") | ||
|
||
module.exports = inspect | ||
|
||
function inspect(observable) { | ||
var pre = document.createElement("pre") | ||
|
||
render(pre, observable()) | ||
|
||
observable(function (value) { | ||
render(pre, value) | ||
}) | ||
|
||
return pre | ||
} | ||
|
||
function render(surface, value) { | ||
surface.textContent = JSON.stringify(value, null, " ") | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.