Skip to content

Instantly share code, notes, and snippets.

@Rich-Harris
Last active September 23, 2015 14:24
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 Rich-Harris/fa549718d85f3552762c to your computer and use it in GitHub Desktop.
Save Rich-Harris/fa549718d85f3552762c to your computer and use it in GitHub Desktop.
ractive-load demo 1
<h1>hello {{name}}!</h1>
<style>
h1 { color: red; }
</style>
<script>
component.exports = {
oninit: function () {
get( 'data.json' )
.then( JSON.parse )
.then( data => this.set( data ) );
}
};
</script>
{
"name": "nadja"
}
function get ( url ) {
return new Promise( function ( fulfil, reject ) {
var xhr = new XMLHttpRequest();
xhr.open( 'GET', url );
xhr.onload = function () {
fulfil( xhr.responseText );
};
xhr.onerror = reject;
xhr.send();
});
}
<main></main>
<script src='http://cdn.ractivejs.org/latest/ractive.js'></script>
<script src='https://rawgit.com/ractivejs/ractive-load/master/dist/ractive-load.js'></script>
<script src='get.js'></script>
<script>
Ractive.load( 'App.html' ).then( function ( App ) {
new App({
el: 'main'
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment