npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ember-change-tracker

v0.0.1

Published

Undo/redo and change detection for Ember.js

Downloads

1

Readme

Ember Change Tracker

Ember Addon providing undo/redo mechanism and change detection. By default it works with Ember Data, but can be easily extended for other persistence libraries.

Installation

ember install ember-change-tracker

Usage

Basic flow

Inject change-tracker service in your route/controller/component:

changeTracker: Ember.inject.service()

Start tracking

Before you allow user to make changes in data, tell Ember Change Tracker to observe affected records. At this stage Ember Change Tracker will create a snapshot of your data and store for comparing in the future.

this.get("changeTracker").begin(this.get("model"), "firstName", "lastName");

The first argument is required and it's the object you'd like to have tracked. After the object you can pass names of the properties you'd like to have tracked (optional). If you don't provide them all object properties will be used.

Alternatively you can use didCreate or didDelete methods with the same arguments as above, to tell Ember Change Tracker that record was created or deleted.

Accept or reject changes

When user accepts changes (e.g. clicks submit button):

this.get("changeTracker").commit(this.get("model"));

When user rejects changes (e.g. clicks cancel button):

this.get("changeTracker").rollback(this.get("model"));

In both methods you can pass multiple objects as arguments to commit or rollback them in one operation (this is important in undo/redo mechanism).

Undo/redo

Every time you call commit method, Ember Change Tracker stores this operation in undo history.

let model = this.get("model");
let changeTracker = this.get("changeTracker");
changeTracker.begin(model, "firstName", "lastName");
model.set("firstName", "John");
changeTracker.commit(model);

You can check if undo is available and undo changes:

changeTracker.get("undoAvailable"); // true
changeTracker.undo();

Then redo is available:

changeTracker.get("redoAvailable"); // true
changeTracker.redo();

Detecting uncommited changes

In some situations you'd like to notify user that their data is not saved and could be lost. Ember Change Tracker makes it quite simple:

this.get("changeTracker").checkForChangedRecords(); // Boolean

This method will return true if there is any changed property in uncommited records.

For less performance impactful detection you can use this computed property:

this.get("changeTracker.hasUncommitedRecords");

This won't compare records properties, just check if there are any records that should be commited or rollbacked.

Using with other persistence libraries

Bu default Ember Change Tracker works with Ember Data. If you'd like to use other persistence library, just extend change-tracker service and define these 3 methods:

import ChangeTracker from "ember-change-tracker/services/change-tracker";

export default ChangeTracker.extend({
  detectProperties(record) {
    // return array of record properties names
  },

  deleteRecord(record) {
    // destroy record
  },

  reincarnateRecord(dead) {
    // create and return an empty record of the same type as provided dead record
  }
});

For inspiration take a look at ChangeTrackerEmberDataAdapterMixin.

Legal

nibynic © 2015

Licensed under the MIT license