Skip to content

Commit

Permalink
2.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
j3tan committed Mar 15, 2016
1 parent 1ba1f58 commit fe78b83
Show file tree
Hide file tree
Showing 23 changed files with 209 additions and 205 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
v2.2.0 - March 14, 2016

* 2.2.0 (Jeff Tan)
* Use recommended wording (Justin Bennett)
* Remove bind, reword test (Justin Bennett)
* Remove unnecessary `bind` call. (Zephraph)
* Support cleaner onmessage handler (Zephraph)
* Add malformed JSON error message (Zephraph)

v2.1.0 - January 31, 2016

* 2.1.0 (Jeff Tan)
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ The last published release:

```
<!-- Recommended: Latest version of T3 -->
<script src="https://cdn.rawgit.com/box/t3js/v2.1.0/dist/t3.js"></script>
<script src="https://cdn.rawgit.com/box/t3js/v2.2.0/dist/t3.js"></script>
<!-- Recommended: Latest minified version of T3 -->
<script src="https://cdn.rawgit.com/box/t3js/v2.1.0/dist/t3.min.js"></script>
<script src="https://cdn.rawgit.com/box/t3js/v2.2.0/dist/t3.min.js"></script>
<!-- jQuery version (IE8 + 1.8.0+ jQuery) -->
<script src="https://cdn.rawgit.com/box/t3js/v2.1.0/dist/t3-jquery.js"></script>
<script src="https://cdn.rawgit.com/box/t3js/v2.2.0/dist/t3-jquery.js"></script>
<!-- jQuery minified version (IE8 + 1.8.0+ jQuery) -->
<script src="https://cdn.rawgit.com/box/t3js/v2.1.0/dist/t3-jquery.min.js"></script>
<script src="https://cdn.rawgit.com/box/t3js/v2.2.0/dist/t3-jquery.min.js"></script>
```
## Upgrade from 1.5.1 to 2.0.0

Expand Down
18 changes: 0 additions & 18 deletions dist/t3-jquery-2.1.0.min.js

This file was deleted.

59 changes: 29 additions & 30 deletions dist/t3-jquery-2.1.0.js → dist/t3-jquery-2.2.0.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! t3-jquery v2.1.0 */
/*! t3-jquery v2.2.0 */
/*!
Copyright 2015 Box, Inc. All rights reserved.
Expand Down Expand Up @@ -577,20 +577,6 @@ Box.Application = (function() {
return receiver;
}

/**
* Creates a new version of a function whose this-value is bound to a specific
* object.
* @param {Function} method The function to bind.
* @param {Object} thisValue The this-value to set for the function.
* @returns {Function} A bound version of the function.
* @private
*/
function bind(method, thisValue) {
return function() {
return method.apply(thisValue, arguments);
};
}

/**
* Simple implementation of Array.prototype.indexOf().
* @param {*[]} items An array of items to search.
Expand Down Expand Up @@ -889,6 +875,26 @@ Box.Application = (function() {
return instances[element.id];
}

/**
* Gets message handlers from the provided module instance
* @param {Box.Application~ModuleInstance|Box.Application~BehaviorInstance} instance Messages handlers will be retrieved from the Instance object
* @param {String} name The name of the message to be handled
* @param {Any} data A playload to be passed to the message handler
* @returns {void}
* @private
*/
function callMessageHandler(instance, name, data) {

// If onmessage is an object call message handler with the matching key (if any)
if (instance.onmessage !== null && typeof instance.onmessage === 'object' && instance.onmessage.hasOwnProperty(name)) {
instance.onmessage[name](data);

// Otherwise if message name exists in messages call onmessage with name, data
} else if (indexOf(instance.messages || [], name) !== -1) {
instance.onmessage(name, data);
}
}

//--------------------------------------------------------------------------
// Public
//--------------------------------------------------------------------------
Expand Down Expand Up @@ -1120,7 +1126,11 @@ Box.Application = (function() {

// <script> tag supports .text property
if (configElement) {
moduleConfig = JSON.parse(configElement.text);
try {
moduleConfig = JSON.parse(configElement.text);
} catch (exception) {
error(new Error('Module with id ' + element.id + ' has a malformed config.'));
}
}

// Cache the configurations for performance, if the module instance has been created
Expand Down Expand Up @@ -1223,32 +1233,21 @@ Box.Application = (function() {
id,
instanceData,
behaviorInstance,
moduleBehaviors,
messageHandlers;
moduleBehaviors;

for (id in instances) {

if (instances.hasOwnProperty(id)) {
messageHandlers = [];
instanceData = instances[id];

// Module message handler is called first
if (indexOf(instanceData.instance.messages || [], name) !== -1) {
messageHandlers.push(bind(instanceData.instance.onmessage, instanceData.instance));
}
callMessageHandler(instanceData.instance, name, data);

// And then any message handlers defined in module's behaviors
moduleBehaviors = getBehaviors(instanceData);
for (i = 0; i < moduleBehaviors.length; i++) {
behaviorInstance = moduleBehaviors[i];

if (indexOf(behaviorInstance.messages || [], name) !== -1) {
messageHandlers.push(bind(behaviorInstance.onmessage, behaviorInstance));
}
}

for (i = 0; i < messageHandlers.length; i++) {
messageHandlers[i](name, data);
callMessageHandler(behaviorInstance, name, data);
}
}

Expand Down
Loading

0 comments on commit fe78b83

Please sign in to comment.