
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
ember-local-storage-proxy
Advanced tools
Library for wrapping HTML5 local storage values as Ember properties.
ember-local-storage-proxy is a library for wrapping HTML5 local storage or session storage values as Ember properties. It is available as an Ember CLI addon.
ember install ember-local-storage-proxy
The ember-local-storage-proxy
module exports the following:
isLocalStorageSupported
, isSessionStorageSupported
: Boolean consts that
represent whether the current browser supports each type of storage.
localStorageProxy(key, defaultValue)
, sessionStorageProxy(key, defaultValue)
: Returns an Ember computed property that is synced with
window.localStorage[key]
or window.sessionStorage[key]
.
key
defaults to the name of the property it is assigned
to.undefined
.In any Ember object (e.g., service, component, controller, or route), use
localStorageProxy
or sessionStorageProxy
to define a proxy property
like this:
// services/settings.js
import Ember from 'ember';
import { localStorageProxy, sessionStorageProxy }
from 'ember-local-storage-proxy';
export default Ember.Service.extend({
// Define a property synced with window.localStorage['settings/enableFoo'],
// with a default value of false.
enableFoo: Ember.computed(localStorageProxy('settings/enableFoo', false)),
// Define a property synced with window.sessionStorage['userId'], with a default
// value of undefined.
userId: Ember.computed(sessionStorageProxy()),
toggleFoo() {
// This will read and write window.localStorage['settings/enableFoo']
// transparently.
this.set('enableFoo', !this.get('enableFoo'));
},
// This will be fired when enableFoo is updated, as usual.
onFooChanged: Ember.observer('enableFoo', function() {
console.log('Foo is %s', this.get('enableFoo') ? 'on' : 'off');
})
});
To use a proxy property elsewhere, e.g., in a component:
// components/my-component/component.js
import Ember from 'ember';
export default Ember.Component.extend({
settings: Ember.inject.service(),
// Optionally define an alias for ease of use.
enableFoo: Ember.computed.alias('settings.enableFoo')
});
In its template:
<!-- components/my-component/template.hbs -->
{{#if enableFoo}}...{{/if}}
Note, however, that Ember cannot detect direct changes to the underlying local /
session storage value. In other words, if your code directly sets
window.localStorage['prefs/enableFoo'] = true
instead of using
set('enableFoo', true)
, a subsequent get('enableFoo')
will still return the
previous value false
, and any observers will fail to fire. As a result, you
should always access or update the value through the proxy property defined via
localStorageProxy
and sessionStorageProxy
.
Properties defined using localStorageProxy
/ sessionStorageProxy
serialize all values to strings via
JSON.Stringify
for storage. When read back, they are deserialized via
JSON.parse
.
For builtin data types, including arrays and plain objects, the encoding and decoding should work transparently.
For custom data types, you would need to first serialize the values to strings or JSON objects before storing them in a proxy property.
Although browser support for HTML5 local
storage is pretty much universal at
this point, ember-local-storage-proxy
will stub out window.localStorage
and
window.sessionStorage
with an empty object in the rare case that they're not
supported. In such cases, all the computed properties defined with
localStorageProxy
/ sessionStorageProxy
can be read from and written
to as normal, except that the values will not be persisted.
FAQs
Library for wrapping HTML5 local storage values as Ember properties.
The npm package ember-local-storage-proxy receives a total of 1 weekly downloads. As such, ember-local-storage-proxy popularity was classified as not popular.
We found that ember-local-storage-proxy demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.