I am beginning to write my first Sencha Touch plugin, and have not been able to find any clear direction (from the official documentation, or from the community) about plugin authoring best practices. In particular, the issues I'd like clarity on are (with a particular emphasis on large, complex plugins):
- namespacing / class naming conventions,
- where extensions should live in the filesystem, and
- including extensions in projects.
To add color to the questions I am about to ask, a little background. I am writing a Sencha Touch 2 plugin to add easy support for authenticating and interacting with a particular API. Unlike a simple plugin for a fancy panel, this is going to require several classes sprinkled all throughout the class hierarchy (a proxy, a reader, a writer, some model tweaks, etc.). And in general, I'd like to echo the general sentiment expressed in this year-old (and unanswered) Ext forum thread: http://www.sencha.com/forum/showthre...best-practices
NAMING / CLASS NAMING CONVENTIONS
The community seems to be divided on this issue. Many plugins are Ext.ux.PluginName. Some are Ext.ux.touch.PluginName. Sometimes people have more classes, and append them: Ext.ux.touch.PluginName.data.proxy.PluginProxy. Some people namespace their plugins under their own brand: PluginCorp.PluginName. Some people sprinkle classes around without an umbrella namespace, like Ext.ux.data.proxy.PluginProxy and Ext.ux.data.writer.PluginWriter.
WHERE SHOULD THE PLUGIN LIVE IN THE FILESYSTEM
Again, no clear consensus. Some sources tell you to put it in sdk/ux and bank on the default class loader finding it like every other class. Some tell you to put it wherever you want, and use Ext.Loader to set the load path.
INCLUDING EXTENSIONS IN PROJECTS
Some people say to put the extension in sdk/ux and rely on the default class loader behavior to find things. Some tell you to put it elsewhere, then point Ext.Loader at it with a custom path. Some sources say to have a single file to include that Ext.require's all dependent files, some depend on the class loader to find each individual file.
After being pulled in many different directions, I don't have an answer, but I do have some thoughts, and some questions:
- Keeping extensions inside the sdk directory is going to make upgrading the sdk much harder than it needs to be. I don't want to have to move a bunch of classes or risk overwriting them when I upgrade, I just want to move a symlink and have it all just work.
- If it doesn't live inside sdk, you need to tell Ext.Loader to look elsewhere for a given namespace. This seems cumbersome in a multi-class plugin if you do not keep all the classes under an umbrella namespace, be it of the Ext.ux.PluginName.foo format, or of the PluginName.foo format.
- Ext.ux.PluginName.foo is more consistent, PluginName.foo is more concise, Ext.ux.foo is just collision-prone and (seemingly, to me) unnecessarilly limiting. Which is best?
It's entirely possible that there is a best practices page out there somewhere and I've simply been unable to find it (if so, please point me at it!). But it seems to me from my fruitless search, and from the wildly inconsistent practices employed in the few Sencha Touch 2 plugins that exist in the marketplace, that there isn't really consensus on the matter. Does anyone else feel this way? Has anybody figured it all out? I'd love to hear thoughts/answers/corrections. For a framework that is usually so organized and well-documented, this area feels scattered and fragmented. I would love plugin authoring to be more accessible and straightforward.