Giter VIP home page Giter VIP logo

ember-storage's Introduction

Ember Storage

A simple but powerful way for managing data that you wish to last through a page reload. This add-on synchronizes data between browser tabs when using localStorage and it is observable.

Live Demo

Build Status

Installation

  • ember install:addon ember-storage

Usage

This service is injected into all routes and components as storage. You may get, set, and observe data on storage just like a regular Ember Object:

export default Ember.Component.extend({
  fullWidth: function() {
    return !this.get('storage.sideBarOpen');
  }.property('storage.sideBarOpen'),
  actions: {
    toggleMenu: function() {
      this.toggleProperty('storage.sideBarOpen');
    },
  },
});
  <!-- some component template -->
  <div id="sidebar" class="{{if storage.sideBarOpen 'open' ''}}">
    sidebar contents
  </div>

  <button {{action 'toggleMenu'}}>Toggle Sidebar</button>

API

  • prefix (property). Set a key prefix. Handy for saving user specific device config. Defaults to 'es'.
  • type (property). Either 'session' or 'local'. Defaults to 'local'. Due to the way sessionStorage works tab sync does not work if type is set to 'session'.
  • clear (function). Clear all data for the specified key. Defaults to the key currently set in prefix.

Examples:

// application route
export default Ember.Route.extend({
  afterModel: function(model) {
    this.currentUserID = model.id;
    // now multiple users could use this device without sharing data
    this.storage.set('prefix', this.currentUserID);
  },
  actions: {
    resetUserPreferences: function() {
      this.storage.clear(this.currentUserID);
    },
  },
});

To create an additional instance (maybe one for sessionStorage) add an initializer to your app:

// app/initializers/session-service.js
import Session from '../services/storage';

var session = Session.create({
  type: 'session',
});

export function initialize(container, application) {
  container.register('service:session', session, {instantiate: false});
  application.inject('route', 'session', 'service:session');
  application.inject('component', 'session', 'service:session');
}

export default {
  name: 'session-service',
  initialize: initialize
};

Running Tests

  • ember test
  • ember test --server

For more information on using ember-cli, visit http://www.ember-cli.com/.

ember-storage's People

Contributors

chvonrohr avatar dknutsen avatar ember-tomster avatar esbanarango avatar jasonmit avatar jerel avatar kategengler avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ember-storage's Issues

Not compatible with Fastboot

TypeError: window.addEventListener is not a function
    at Proxy.init (/app/tmp/broccoli_merge_trees-output_path-aa52PBSo.tmp/assets/addon-tree-output/ember-storage/services/storage.js:33:1)

Tested on Ember 3.5 with ember-storage 2.0.

Update ember-cli-babel to 6

Hi, I love your plugin, however it's one of the few that are still using ember-cli-babel 5 in our project. Using version 6 would allow the removal of ember-cli-shims as well as fix some deprecation warnings. More information on that could be seen here.

P.S. See more issues of that kind:

mharris717/ember-drag-drop#121

Ember 2.12.0 testing

I just upgraded an app to 2.12.0 (from 2.11.3) and now all of my tests that cover services using ember-storage are failing. However, the addon still works, there just seems to be an incompatibility with ember's test practices.

The real question: is this addon still supported, or is it officially no longer maintained? I can make assumptions by the lack of updates, but I guess I would like an official message.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.