Created
March 31, 2011 16:27
-
-
Save Olical/896697 to your computer and use it in GitHub Desktop.
Blog post: Data normalisation with Mappa
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
var newsFeed = { | |
meta: { | |
foo: 'bar', | |
etc: 12345 | |
}, | |
results: [ | |
{ | |
t: 'New GCC compiler', | |
more: { | |
u: 'http://reddit.com/' | |
} | |
}, | |
{ | |
t: 'Some other news', | |
more: { | |
u: 'http://bbc.co.uk/' | |
} | |
} | |
] | |
}; | |
var webDevelopers = { | |
title: 'Oliver Caldwell', | |
url: 'http://flowdev.co.uk/' | |
} |
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
// First we add an alias so we can access the object under the name we want | |
// Lets call it tb, short for toolbox. | |
Mappa.addAlias('tb'); | |
// From now on we will reference the Mappa object by its alias, tb. | |
// Lets map to our animation function | |
tb.addMap('animate', someAnimateFunction); | |
// Now lets map to our JSON functions | |
tb.addMap('json', { | |
encode: JSON.stringify, | |
decode: JSON.parse | |
}); |
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
Mappa.addMap('newsFeed', { | |
title: 'results.t', | |
url: 'results.more.u' | |
}); | |
Mappa.addMap('webDevelopers', { | |
title: 'title', | |
url: 'url' | |
}); |
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
New GCC compiler (http://reddit.com/) | |
Some other news (http://bbc.co.uk/) | |
Oliver Caldwell (http://flowdev.co.uk/) |
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
var norm = Mappa.normalise({ | |
newsFeed: newsFeed, | |
webDevelopers: webDevelopers | |
}); | |
for(var i = 0; i < norm.length; i++) { | |
console.log(norm[i].title + ' (' + norm[i].url + ')'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment