JSFiddle - React, Tailwind, and code Playground
by ifandelse
HTML
<script src="https://raw.github.com/gist/2137980/5830d81c0c21364b973414896eca35395236cc81/amplify.js"></script>
JavaScript
// Define what a getTweets request looks like... url, dataType, etc
amplify.request.define( "getTweets", "ajax", {
url: "http://twitter.com/status/user_timeline/{userName}.json?count={count}&callback=?",
dataType: "json",
type: "GET"
});
// You can redefine the request to mock out the response
amplify.request.define( "getTweets", function ( settings ) {
settings.success([
{ text: "Test Tweet 1" },
{ text: "Test Tweet 2" },
{ text: "Test Tweet 3" },
{ text: "Test Tweet 4" },
{ text: "Test Tweet 5" }
]);
});
// Subscribe to the "applciation.started" topic that is published later
amplify.subscribe( "application.started", function ( data ) {
// Writes out the message that was passed in the Publish
console.log( data.message );
// Request "getTweets" passing in necessary data which
// is used in URL substitution
amplify.request( "getTweets",
{ userName: "AmplifyJS", count: "5" },
function ( tweets ) {
// Store the rich tweets array to persistent storage
amplify.store( "tweets", tweets );
// Retreive the tweets array from storage and write
console.log( amplify.store( "tweets" ) );
});
});
// Kick off the whole process by publishing message with data
amplify.publish( "application.started", {
message: "Hello World!"
});