0.1.0 • Published 6 years ago

ember-buffered-array-proxy v0.1.0

Weekly downloads
106
License
MIT
Repository
github
Last release
6 years ago

ember-buffered-array-proxy Build Status npm version

An Ember Array Proxy (and mixin) the enables change buffering. Ever need to "hold back" array changes before they propagate? If so this may be the project for you.

This project follows similar API structure as ember-buffered-proxy.

Usage

ember install ember-buffered-array-proxy
import BufferedArrayProxy from 'ember-buffered-array-proxy/proxy';

const content = [ 'A' ];
const buffer = BufferedArrayProxy.create({ content });

buffer.get('firstObject'); // => 'A'
buffer.addObject('B');

buffer.objectAt(1); // => 'B'
buffer.toArray(); // => ['A', 'B']

buffer.get('hasChanges'); // => true
buffer.get('changes'); // => (get an object describing the changes) -- { added: ['B'], removed: [] }

buffer.applyBufferedChanges();

buffer.toArray(); // => ['A', 'B']
content.toArray(); // => ['A', 'B']
buffer.get('hasChanges'); // => false

buffer.removeObject('A');
buffer.get('changes'); // => { added: [], removed: ['A'] }
buffer.hasChanged(); // => true

buffer.discardBufferedChanges();

buffer.toArray(); // => ['A', 'B']
content.toArray(); // => ['A', 'B']
buffer.hasChanged(); // => false

You can also use these shorter method names

buffer.discardChanges(); // equivalent to buffer.discardBufferedChanges()
buffer.applyChanges();   // equivalent to buffer.applyBufferedChanges()

Or you can grab the mixin directly

import BufferedArrayMixin from 'ember-buffered-array-proxy/mixin';

const content = ['A']
const buffer = ArrayProxy.extend(BufferedArrayMixin).create({ content });

// same as above