dimanche 18 décembre 2016

Fetch new data from API in jQuery plugin's callback

I am new to ember, so please treat me like a fool. What I'm trying to do first is to understand the concept.

In my application I heavily rely on few jQuery plugins they fetch new portion of data in their callbacks, that's how these plugins are designed, but I am not sure how can I trigger them to fetch a new portion of data from API passing to API updated query parameters after plugin has been rendered.

I have wrapped the plugin in a component, in component's template I send data to it as (I use emblem.js syntax here)

= plotly-chart chartData=model

In model I have

//app/models/data-points.js

import DS from 'ember-data';

export default DS.Model.extend({
    // time: DS.attr(),
    ch1:  DS.attr(),
    ch2:  DS.attr(),
    ch3:  DS.attr(),
    temperature:  DS.attr(),
});

And then in component itself I fetch data

//app/components/plotly-chart.js

dataPoints: Ember.computed.map('chartData', function(item){
    return item.getProperties('ch1', 'ch2', 'ch3', 'temperature');
}),

and make some manipulations with data, which isn't so important for the question itself.

Ah, and I have a route graph/ which later calls that component

//app/routes/graph.js

import Ember from 'ember';

export default Ember.Route.extend({
    queryParams: {
        start_timestamp: {
            refreshModel: true
        },
        end_timestamp: {
            refreshModel: true
        }
    },
    model(params) {
        return this.get('store').query('data-point', params);
    }
});

So as you see I have tried to fetch new properties via query params, finally it works great if I just update the url in browser, but now can I trigger new call to API and fetch new data and get this new data in a component itself?

Also I'm struggling to understand what role controllers play in all of these. It is mentioned that controllers will be deprecated soon, but still used here http://ift.tt/2hORzpq My code seems to work without controllers, so this is really confusing.

Also I suspect maybe I should use services for what I'm trying to achieve, but not sure how.

Ember experts, could you please point me into a right direction? The most important thing is how to fetch new portion of data from API with updated query parameters (query parameters to API itself, not nessesarely the ember application, but I suspect in ember-data it is the same thing? or not %) %) %)).




Aucun commentaire:

Enregistrer un commentaire