Socket
Book a DemoInstallSign in
Socket

ember-cli-cookie

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ember-cli-cookie

Wrap $.cookie in Ember goodness

0.2.0
latest
Source
npmnpm
Version published
Weekly downloads
108
2.86%
Maintainers
1
Weekly downloads
 
Created
Source

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
}

#setCookie(key, value, options)

Use this function to set a cookie, eg:

// /controllers/test.js

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

      this.cookie.setCookie('my-key', 'my-value', { expires: 7, path: '/' })
        .then(function() {
          self.transitionToRoute('success');
        });
    }
  }
});

#getCookie(key)

Use this function to get a cookie, eg:

// /controllers/test.js

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

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

#removeCookie(key)

Use this function to remove/delete a cookie, eg:

// /controllers/test.js

export default Ember.Controller.extend({
  actions: {
    testAction: function() {
      this.cookie.removeCookie('my-key');
    }
  }
});

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

  • Aaron Chambers (achambers@gmail.com)

Keywords

ember-addon

FAQs

Package last updated on 26 Feb 2016

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.