Sunday 15 June 2014

Best plugin development practices to avoid polluting jQuery namespace? -


I have created a jQuery plugin that allows the user to interact with a tree (creating, updating, deleting the node) gives. There are at least one dozen ways to interact with the tree. Ideally, I do not want to pollute the jQuery namespace with all these tree-specific methods because I now offer an extra opportunity for a namespace collision in every way. I just want a method to activate the plugin and so I'm looking at the refactor.

  $ ('ol # tree'). Trees (options) // Just a single jQuery method invoice ('Li # Item 6') // ... However, we have this subsidiary method $ ('ol # tree'). Adendod (node) // ... and this is a $ ('li # item2') extension branch () // ... and this one, etc.  

What are some practices to highlight an active DOM element and an interface for its sub-do not contaminate the Japanese namespace?

I have worked to save the returning jQuery object while creating a tree.

  var tree = $ ('ol # tree') tree () .;  

The object of this tree will be expanded to include methods only. Unfortunately, the tree is being manipulated regularly, it is the risk of having the position of that object Sends out the synchronization with the status of parent dom entry and its sub-elements. I'm not sure that trying to maintain the state in that object is worth it, since there will always be a current situation in the DOM.

I have considered using a namespace (via John Raisig):

How do you control this problem? Can you talk to some existing plugins that address this problem whose code I could learn?

Small and crisp name! Not boring trees , but for example Niketry (Hey, this is just an idea)! Put the interface in the name. Like this:

$ ("ol # tree"). Nicetree.appendNode (node); $ ("Ol # tree") nicetree.item ("Lee # ITEM2") expandBranch () ..

Another idea is this object that comes back as your offer, but do not update this object. This object is only a reference to the real object or dome, it adds a layer of indirection and it can not be acceptable for you.

I would like both solutions as a plugin user, but I like the first one.


No comments:

Post a Comment