model/localStorage Cotonic
model/localStorage
get/+key
Gets item key from localStorage. Returns the content as payload.
cotonic.broker.call("model/localStorage/get/a")
.then(
function(m) {
console.log("a is set to:", m.payload)
}
);
post/+key
Update, or insert message under key in localStorage.
cotonic.broker.publish("model/localStorage/post/a", "Hello world!");
delete/+key
Delete item stored under key from localStorage.
cotonic.broker.publish("model/localStorage/delete/a");
event/+key
Subscribe to changes or deletions from localStorage. When the message payload
is null the item is delete. Otherwise the payload is set to the
newly updated value.
cotonic.broker.subscribe("model/localStorage/event/+key",
function(m, a) {
if(m.payload === null) {
console.log("localStorage item:", a.key, "deleted");
else {
console.log("localStorage item:", a.key, "changed", m.payload);
}
});
=> Logs update to localStorage elements.
event/ping
When the localStorage model is enabled it publishes a retained message
under the topic model/localStorage/event/ping. It makes it
possible to detect the localStorage model is enabled.
cotonic.broker.subscribe("model/localStorage/event/ping",
function() {
console.log("localStorage is enabled");
});