Skip to content

Instantly share code, notes, and snippets.

@Willmo36
Created February 5, 2016 16:41
Show Gist options
  • Save Willmo36/b2f8e2a8ab5f6f1ec814 to your computer and use it in GitHub Desktop.
Save Willmo36/b2f8e2a8ab5f6f1ec814 to your computer and use it in GitHub Desktop.
esnextbin sketch
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>ESNextbin Sketch</title>
<!-- put additional styles and scripts here -->
</head>
<body>
<!-- put markup and other contents here -->
</body>
</html>
// write ES2015 code and import modules from npm
// and then press "Execute" to run your program
import Baobab from "baobab";
const tree = new Baobab({
dash: {
has: {
lots: {
of: {
data: true,
totalData: Baobab.monkey({
cursors: {
hasData: ["dash", "has", "lots", "of", "data"]
},
get: function(data) {
console.log("in monkey", tree.get());
return data.hasData ? "SO MUCH DATA" : "no data :("
}
})
}
}
}
}
});
const hasData = tree.select(["dash", "has", "lots", "of", "totalData"]);
hasData.on("update", x => console.info("update ",x.target.get()));
setTimeout(() => {
console.log("with data")
tree.set({
dash: {
has: {
lots: {
of: {
data: false
}
}
}
}
});
}, 500);
setTimeout(() => {
console.log("without data")
tree.set({
dash: {
has: {
nodata: true
}
}
});
}, 1000);
setTimeout(() => {
console.log("with data")
tree.set({
dash: {
has: {
lots: {
of: {
data: true
}
}
}
}
});
},1500);
{
"name": "esnextbin-sketch",
"version": "0.0.0",
"dependencies": {
"baobab": "2.3.3"
}
}
"use strict";
var _baobab = require("baobab");
var _baobab2 = _interopRequireDefault(_baobab);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var tree = new _baobab2.default({
dash: {
has: {
lots: {
of: {
data: true,
totalData: _baobab2.default.monkey({
cursors: {
hasData: ["dash", "has", "lots", "of", "data"]
},
get: function get(data) {
console.log("in monkey", tree.get());
return data.hasData ? "SO MUCH DATA" : "no data :(";
}
})
}
}
}
}
}); // write ES2015 code and import modules from npm
// and then press "Execute" to run your program
var hasData = tree.select(["dash", "has", "lots", "of", "totalData"]);
hasData.on("update", function (x) {
return console.info("update ", x.target.get());
});
setTimeout(function () {
console.log("with data");
tree.set({
dash: {
has: {
lots: {
of: {
data: false
}
}
}
}
});
}, 500);
setTimeout(function () {
console.log("without data");
tree.set({
dash: {
has: {
nodata: true
}
}
});
}, 1000);
setTimeout(function () {
console.log("with data");
tree.set({
dash: {
has: {
lots: {
of: {
data: true
}
}
}
}
});
}, 1500);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment