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-deep-buffered-proxy

v0.0.10

Published

Change buffering proxy for Ember Objects, arrays, promises

Downloads

6

Readme

Ember Deep Buffered Proxy

Build Status Ember Observer Score npm version

Wrap your data in a proxy that buffers all changes - meaning that you can control when and whether they get applied on source data.

There is plenty of buffer proxy or changeset Ember addons, this one tries to unite all these ideas in one addon:

  • Supports Ember Objects, POJOs, Arrays, Ember Arrays,
  • Supports promises,
  • Supports nested objects,
  • Lists all changes, detects dirtiness,
  • Allows you to apply or discard changes.

If you are using EmberData, there is a more specialized addon called Ember Data Fork.

Compatibility

  • Ember.js v2.12 or above
  • Ember CLI v2.13 or above
  • Node.js v10 or above

Installation

ember install ember-deep-buffered-proxy

Usage

import buildProxy from 'ember-deep-buffered-proxy';

let model = {
  name: 'Cookie Monster',
  address: {
    street: 'Sesame St.'
  },
  friends: [
    { name: 'Bert' },
    { name: 'Ernie' }
  ]
};

let buffer = buildProxy(model);

buffer.set('name', 'Big Bird');
buffer.get('address').set('street', 'Sesame Street');
buffer.get('friends').popObject();
buffer.get('friends').addObject({ name: 'Elmo' });

// model has not changed

buffer.dbp.hasChanges; // true
buffer.dbp.applyChanges();

// model received the changes

buffer.dbp.hasChanges; // false

Namespace

To prevent attribute name collision, all buffer methods and attributes are wrapped inside an object that is available under dbp key. If you don't like this name, you can set your own namespace in the configuration.

What is considered a change?

By default Ember Deep Buffered Proxy uses JSON serialization and strict equality to compare old and new values. That means that for example two Date instances are considered same as long as they have same time value. If this mechanism doesn't work for you, you can always provide your own serialization method in options:

let buffer = buildProxy(model, {
  serialize(v) {
    return v; // use actual value without any serialization
  }
});

Extending

Ember Deep Buffered Proxy ships with two classes: ObjectProxy and ArrayProxy. Each of them has its own driver class (ObjectProxy.Driver and ArrayProxy.Driver) - that's the class that gets instantiated under the namespace hook. Here's a general idea how to extend these classes or define custom proxy class:

import { isArray } from '@ember/array';
import buildProxy, { ObjectProxy, ArrayProxy } from 'ember-deep-buffered-proxy';

const MyObjectProxyDriver = ObjectProxy.Driver.extend({
});

const MyObjectProxy = ObjectProxy.extend({
}).reopenClass({
  Driver: MyObjectProxyDriver
});

export default function(content) {
  return buildProxy(content, {
    proxyClassFor(obj) {
      return isArray(obj) ? ArrayProxy : MyObjectProxy;
    }
  });
}

Configuration

To override default configuration just define your settings in config/environment.js under deepBufferedProxy key. These are all available options:

{
  namespace: 'dbp' // key under which buffer methods and attributes are available
}

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.