UNPKG

box-chrome-sdk

Version:

A Chrome App SDK for the Box V2 API

27 lines (24 loc) 1.12 kB
/** * @module chrome.storage An Rx abstraction of the * [chrome.storage API](https://developer.chrome.com/extensions/storage) */ var storage = angular.module('chrome.storage', ['chrome', 'rx']); storage.service('chromeStorage', ['chrome', 'rx', function(chrome, rx) { /** * Gets an item from the Chrome local item store. * @param {String} name The name of the item to get from the local item store. * @returns {Observable} An observable containing the object from the local item store with the given name. */ this.getLocal = function(name) { return rx.Observable.fromChromeCallback(chrome.storage.local.get, null, chrome.storage.local)(name) .map(function(result) { return result[name]; }); }; /** * Sets an item in the Chrome local item store. * @param value * @returns {Observable} An observable containing a boolean value indicating whether the storage was successful. */ this.setLocal = function(value) { return rx.Observable.fromChromeCallback(chrome.storage.local.set, null, chrome.storage.local)(value); }; }]);