ivanvanderbyl / maximum-plaid

Template driven data visualisation for Ember
http://maximum-plaid.com/
MIT License
74 stars 9 forks source link

updated pairBy can listen to array object changes #39

Open nsharrok opened 8 years ago

nsharrok commented 8 years ago

This PR is related to issue #38 An observer added to the pair-by.js helper allows for dynamic chart updating. addon/helpers/pair-by.js

import Ember from 'ember';
import Helper from 'ember-helper';
import observer from 'ember-metal/observer';
const { assert } = Ember;

export default Helper.extend({
    compute(params) {
        assert('pair-by requires at least 2 arguments: key, data', params.length >= 2);
        let data = params.pop();
        this.set('array', data);
        assert('last argument must be an array of objects', Ember.isArray(data));
        let [...keys] = params; 

        return data.map((d) => {
            return keys.reduce((acc, k, index) => {
                acc[index] = d[k];
                return acc;
            }, []);
        });
    },
    contentDidChange: observer('array.[]', function() {
        this.recompute();
    })
});
ivanvanderbyl commented 8 years ago

This PR doesn't seem to contain the correct commits, the diff is only for some package changes.