Skip to content

Instantly share code, notes, and snippets.

@devdays
Created December 20, 2014 18:22
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 devdays/543f61121796a8cc1d6d to your computer and use it in GitHub Desktop.
Save devdays/543f61121796a8cc1d6d to your computer and use it in GitHub Desktop.
Singe Page App - amplify publish sample
var app = {};
app.product = function () {
this.create = function (productName, category, price) {
var product = {
productName: productName,
category: category,
price: price
};
// publish that you have added a product
amplify.publish('productCreated', product);
return product;
};
this.all = function () {
var store = amplify.store("productsStore");
if (store === undefined) {
store = new Object();
store.products = new Array();
amplify.store("productsStore", store);
}
return store;
};
this.add = function (product) {
var data = this.all();
data.products.push(product);
// store the new data
amplify.store("productsStore", data);
// publish that the product store has been updated
amplify.publish("productsStoreUpdated");
};
this.clear = function () {
amplify.store("productsStore", null);
amplify.publish("productsStoreUpdated");
};
return {
create: create,
all: all,
add: add,
clear: clear
}
}(amplify);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment