Skip to content

bleib1dj/ember-cli-cookie

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ember-cli-cookie

Wrap $.cookie in Ember goodness

Motivation

To try and remove external dependencies from my Ember CLI apps with a Promise aware object wrapper.

Synopsis

This addon is designed to help pushing the external dependencies of cookies as far from my Ember CLI app as possible. By injecting this object where cookie access is needed, my Ember code can just deal with an Ember object. This also means that I can inject mock objects in during tests to simulate setting and getting cookies.

Installation

From within your Ember CLI application, run:

npm install --save-dev ember-cli-cookie

Usage

In an initializer, inject the cookie object where needed:

// /initializers/test.js
export function initialize(container, application) {
    application.inject('controller', 'cookie', 'cookie:main');
}

export default {
    name: 'test-initializer',
    after: ['cookie'],
    initialize: initialize
}

#set(key, value)

Use this function to set a cookie, eg:

// /controllers/test.js

export default Ember.Controller.extend({
  actions: {
    testAction: function() {
      var self = this;

      this.cookie.set('my-key', 'my-value')
        .then(function() {
          self.transitionToRoute('success');
        });
    }
  }
});

#get(key)

Use this function to get a cookie, eg:

// /controllers/test.js

export default Ember.Controller.extend({
  actions: {
    testAction: function() {
      var self = this;
      this.cookie.get('my-key');

      if (!token) {
        this.transitionTo('login');
      }
    }
  }
});

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality.

Maintainers

About

Wrap $.cookie in Ember goodness

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%