Skip to main content link. Accesskey S
  • Overview ▾ Show Menu▼
  • IBM
  • Connections Developers
  • Home
  • Dev Guide
  • API Docs
  • SDK
  • Community
Search
SDK > SDK docs > Writing relocatable JavaScript code
  • Share Show Menu▼
  • Subscribe Show Menu▼

About the Original Author

Click to view profileIBM contributorIBM
Contribution Summary:
  • Articles authored: 823
  • Articles edited: 758
  • Comments Posted: 0

Recent articles by this author

Removing multiple members

To delete multiple members from an activity with one API request, send an Atom feed as part of a delete request to the activity ACL.

Adding multiple members

To add multiple members to an activity with one API request, send an Atom feed document containing entries of the new members to be added to the activity ACL.

Moving Nodes Under Different Activities or Nodes

To move an activity node to another activity node, use an HTTP POST request.

Moving fields between nodes

To move a field to another activity node, use an HTTP PUT request.

IBM Connections Event Reference - Files

Files Events Event data is provided using the following conventions. Refer to the EventSPIic50Event SPI for details about these event data objects, how to retrieve them from the event object, and how to get additional information from these objects themselves. The event can be shared ...
Writing relocatable JavaScript code
Added by IBM contributorIBM | Edited by IBM contributorPhilippe Riand on May 24, 2013 | Version 3
  • Edit
  • More Actions Show Menu▼
Rate this article 1 starsRate this article 2 starsRate this article 3 starsRate this article 4 starsRate this article 5 stars
expanded Abstract
collapsed Abstract
No abstract provided.
The SDK is a fast evolving library with frequent updates. Even though we advise developers to keep up-to-date and consume the latest available release, it is not always possible. In the worse case, different components on a single page might require different versions of the SDK to work properly.
Fortunately, the AMD syntax has all the mechanism in place to allow multiple releases of a library. It simply requires some discipline from the developers and have them follow a simple set of rules. When this is properly implemented, multiple releases of the SDK can co-exist in the same page. They are then referenced by different root names, coming from different server contexts.
Here is an example:

require([sbt/dom], function(dom) {...});
require([mysbt/dom], function(dom) {...});

Two version of the same library are being used here, sbt and mysbt. They both provide a dom module.

Here is the set of rules to observe to make it possible:

1- Don't name a module in its define() statement
The actual module name is defined by the relative path from the server context path.

2- Use relative paths when accessible a module in the same library
Similary to directories, '.' and '..' can be used to access modules using relative paths.
As an example, suppose that sbt/xpath requires sbt/xml, then the following syntax should be preferred:

define(['./xml'], function(dom) {...});
instead of
define(['sbt/xml'], function(dom) {...});

Then the modules can be safely relocated from sbt to mysbt, as there is no hard coded references to sbt.

3- Don't name classes when using declare()
The SDK uses the declare() syntax from dojo to create pseudo JavaScript classes. In order to make the code relocatable, then the classes should be declared anonymous within their own AMD module. Then, the classes is accessed through its module name.
Here is an example:

// MyModule.js definition
define(['./xml','./xpath'], function(dom,xpath) {...}
	var myClass = declare(null, {
	...
	});
	return myClass;
);

// MyModule.js consumption
require([./MyModule'], function (Module) {
	var m = new MyModule();	
	...
}



4- Consuming dijits
When consuming a dijit from the SDK in your code, refer to the module name as opposed to the class name. Actually, class names won't work as all the class are anonymous:

<div data-dojo-type="sbt/controls/grid/connections/CommunityGrid"></div>
instead of
<div data-dojo-type="sbt.controls.grid.connections.CommunityGrid"></div>

When developing a new dijit, the developer should make sure that the AMD module returns the class, as shown in 3-

5- Dojo 1.4-1.6
The AMD loader provided by the SDK overrides the default dojo.getObject() function. The new implementation first check if the requested name contains a slash '/'. If so, then it returns the result of the corresponding AMD module. Else, it default to the legacy behavior.


References:
http://dojotoolkit.org/documentation/tutorials/1.8/modules/
http://dojotoolkit.org/documentation/tutorials/1.8/declare/

Parent topic: Conventions and best practices in JavaScript

  • Edit
  • More Actions Show Menu▼


expanded Attachments (0)
collapsed Attachments (0)
Edit the article to add or modify attachments.
expanded Versions (1)
collapsed Versions (1)
Version Comparison     
VersionDateChanged by              Summary of changes
This version (3)May 24, 2013, 5:20:20 PMPhilippe Riand  IBM contributor
expanded Comments (0)
collapsed Comments (0)
Copy and paste this wiki markup to link to this article from another article in this wiki.
Go ElsewhereStay ConnectedHelpAbout
  • IBM Collaboration Solutions wikis
  • IBM developerWorks
  • IBM Software support
  • Twitter LinkIBMCnxDev on Twitter
  • ForumsIBMCnxDev on Stack Overflow
  • FacebookIBMSocialBizUX on Facebook
  • ForumsIBM Collaboration Solutions product forums
  • Community LinkThe Social Lounge
  • Wiki Help
  • Forgot user name/password
  • Wiki design feedback
  • Content feedback
  • About the wiki
  • About IBM
  • Privacy
  • Accessibility
  • IBM Terms of use
  • Wiki terms of use