Skip to content

Instantly share code, notes, and snippets.

@meric
Created April 2, 2015 01:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meric/a77f6633e023310be114 to your computer and use it in GitHub Desktop.
Save meric/a77f6633e023310be114 to your computer and use it in GitHub Desktop.
immstruct building pattern
// Content.js
Content.construct = function(statics, cursor, {country}) {
cursor = cursor.update(() => Immutable.fromJS({
country: (country || ""),
url: statics.routePath,
}))
return new Promise((resolve, reject) =>
setTimeout(() => resolve("Hello World"), 500))
.then((value) => cursor.cursor('world').update(() => value))
}
// ProfilePageList.js
ProfilePageList.construct = function(statics, cursor) {
cursor = cursor.update(() => Immutable.fromJS({
crumbs: [
{text: "Home", url: "/"},
{text: "About", url: "/?1"}
],
title: "My Website"
}))
return Content.construct(statics, cursor.cursor('contentState'),
{country: "Australia"})
}
// main
ProfilePageList.construct({
routeParams: parameters,
routePath: window.location.pathname
}, structure.cursor())
.then(() => {
var cursor = structure.cursor();
document.title = cursor.cursor('title').deref();
})
.catch(console.error);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment