Singe Page App - amplify publish sample
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 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