sparkartgroup-archive / sparkart.js

Easily interact with Sparkart's APIs via Javascript.
1 stars 0 forks source link

Usage with RequireJS #64

Open pushred opened 10 years ago

pushred commented 10 years ago

It's unclear how to call Sparkart.js methods and bind to events for a fanclub instantiated within a RequireJS module. Since instantiation and many of the events rely upon asynchronous calls to a fanclub it doesn't seem like a vanilla RequireJS setup supports the ability of exporting that fanclub object and depending upon it in other modules. I presume this would require blocking that code until the async dependency is ready.

I noticed that an async plugin exists, presumably for similar issues with other libraries. But it looks like it also loads the library externally. We could do that as well since we offer it at http://js.sparkart.net/sparkart.js/current.js, but it's something that could also be included in a fanclub bundle. The asynchronous nature of it is really the calls to our API endpoints.

Currently all method calls/event binding must remain in the same RequireJS module, but this seems to negate it's benefits.

Have any experience with this sort of scenario @rxaviers?

rxaviers commented 10 years ago

As we skyped (for the record), the end that depends on sparkart.js and other libraries (eg. tabs) should require them both. Like:

define(["sparkart", "tabs"], function(Sparkart){
  var sparkart = new Sparkart({
    template: function(data) {
      render(data).tabs();
    }
  })
})