Git Product home page Git Product logo

ember-state-services's Introduction

ember-state-services Build Status

This addon introduces a state management pattern using services, which allows them to serve multiple consumers (often components).

An example could be a master/detail experience where the detail view is a component which allows editing of content. It would be unfortunate if navigating would lose un-saved changes; it would also be unfortunate if the state between the edit components were to leak between each other. Instead, the service issues a unique state per reference key, which keeps management safe and easy.

Collaborators:

  • services: singletons which maintain and issue out states to consumers
  • states: non-singletons, typically key'd to a model which provide ephemeral state.

Usage

service

// app/services/email-edit.js
import Ember from 'ember';
import StateMixin from 'ember-state-services/mixin';

export default Ember.Object.extend(StateMixin, {
  stateName: 'email-edit'
});

state

// app/states/email-edit.js
import BufferedProxy from 'ember-buffered-proxy/proxy';

export default BufferedProxy.extend();

learn more about buffered proxy: https://github.com/yapplabs/ember-buffered-proxy

component

import Ember from 'ember';

export default Ember.Component.extend({
  tagName: 'form',
  editEmailService: Ember.inject.service('email-edit'),
  state: Ember.computed('email', function() {
    return this.editEmailService.stateFor(this.get('email'));
  }).readOnly(),

  actions: {
    save() {
      this.get('state').applyChanges();
      this.sendAction('on-save', this.get('email'));
    },

    cancel() {
      this.get('state').discardChanges();
      this.sendAction('on-cancel', this.get('email'));
    }
  }
});

template

<label>Subject: {{input value=state.subject}}</label><br>
<label>from:   {{input value=state.from}}</label><br>
<label>body:   {{textarea value=state.body}}</label><br>

Installation

  • ember install ember-state-services

Example

Running Tests

  • ember test
  • ember test --server

Building

  • ember build

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

ember-state-services's People

Contributors

jayphelps avatar stefanpenner avatar thoov avatar blimmer avatar serabe avatar alexdiliberto avatar hjdivad avatar et avatar kategengler avatar iamolivinius avatar ember-tomster avatar

Watchers

James Cloos avatar greyhwndz avatar

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.