Giter VIP home page Giter VIP logo

ember-autosave's Introduction

Ember Autosave

This ember-cli addon provides a proxy object that saves a wrapped model when properties are set.

Installation

ember install:addon ember-autosave

Usage

There are two primary ways to use the addon: with the computed property macro or by creating an AutosaveProxy object.

Using the Computed Property

The ember-autosave package provides a computed property macro to wrap a property in an AutosaveProxy.

import Ember from 'ember';
import { computedAutosave } from 'ember-autosave';

export default Ember.Controller.extend({
  post: computedAutosave('model')
});

Using AutosaveProxy

You may also use the AutosaveProxy object directly.

import Ember from 'ember';
import { AutosaveProxy } from 'ember-autosave';

export default Ember.Route.extend({
  setupController: function(controller, model) {
    autosaveProxy = AutosaveProxy.create({ content: model });
    controller.set('model', autosaveProxy);
  }
});

Advanced Configuration

By default, an AutosaveProxy object will call save() on its content once input stops for 1 second. You can configure this behavior globally or for each AutosaveProxy instance.

Global Configuration

// Using an initializer is recommended

import Ember from 'ember';
import { AutosaveProxy } from 'ember-autosave';

export function initialize() {
  AutosaveProxy.config({
    saveDelay: 3000, // Wait 3 seconds after input has stopped to save
    save: function() {
      // The context here is the wrapped model
      this.mySpecialSaveMethod()
    }
  });
}

export default {
  name: 'setup-ember-autosave',
  initialize: initialize
};

Per Instance Configuration

With the computed property:

import Ember from 'ember';
import { computedAutosave } from 'ember-autosave';

export default Ember.Controller.extend({
  post: computedAutosave('model', { saveDelay: 3000 })
});

With the AutosaveProxy object.

import Ember from 'ember';
import { AutosaveProxy } from 'ember-autosave';

export default Ember.Route.extend({
  setupController: function(controller, model) {
    autosaveProxy = AutosaveProxy.create({ content: model }, { saveDelay: 3000 });
    controller.set('model', autosaveProxy);
  }
});

Demo

To see a demo of this addon you can clone this repository, run ember server, and visit http://localhost:4200 in your browser.

ember-autosave's People

Contributors

mitchlloyd avatar nhemsley avatar

Watchers

 avatar  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.