Wrapping npm modules as Ember Addons

194 Views Asked by At

I am working on an Ember application and would like to create an ember addon for it. The use case for the addon would be to create an ontology tree for the consuming application. The repository for the module I would like to make into an addon is inspire tree and I am needing to wrap this module.

Here is the Inspire Tree Repository.

I am aware of the general structure of Ember addons and an idea on how to make one, but if anyone can give advice on best practices & how to wrap npm modules as addons in general would be very helpful.

2

There are 2 best solutions below

0
On BEST ANSWER

Instead of wrapping the npm module, give https://github.com/ef4/ember-auto-import a try in your app and use via import InspireTree from 'inspire-tree'; once you've installed that module via npm.

0
On

I think the steps to creating a good addon that wraps an external library follows these steps (I’ll use ember-moment as a good use case):*

  1. Do you need more than just the methods/objects from the underlying library? If not, just import the library.

  2. Does the library provide relatively stateless Ui components? If so, start making ember components! A good example of this is something like ember moment {{moment-format date}}. No matter what you’re doing, you’re always going to get the same result out. Other examples: number formats, link sharing, font-awesome.

  3. Does this library depend on a bunch of application specific business logic? If so, if you make it an addon, it may not be worth the overhead in maintence.

Take what I say with a grain of salt, because I maintain 0 addons.

*note: I have no idea whatsoever what this library you’re referencing is, nor did I look it up, but these are the best practices.