Skip to content

Commit

Permalink
Merge remote-tracking branch 'antranig/FLUID-5866'
Browse files Browse the repository at this point in the history
* antranig/FLUID-5866:
  FLUID-5866: Removed now unused argument "root" from fluid.parsePriorityRecords and added documentation following work with ADTKINS.
  FLUID-5866: Removing implementation of "fluid.priorityHolder" and rewriting test case to demonstrate that it is unnecessary
  • Loading branch information
cindyli committed Apr 20, 2016
2 parents 366c6d0 + 1d34764 commit 6b79a75
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 40 deletions.
17 changes: 0 additions & 17 deletions src/framework/core/js/DataBinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -916,23 +916,6 @@ var fluid_2_0_0 = fluid_2_0_0 || {};
}
});

/** Utility grade to compute and hold priorities for model listeners **/
fluid.defaults("fluid.priorityHolder", {
gradeNames: "fluid.component",
members: {
priorities: "@expand:fluid.priorityHolder.expand({that}.options.priorities)"
}
});

fluid.priorityHolder.expand = function (priorities) {
var array = fluid.parsePriorityRecords(priorities, "priorityHolder entry", true);
var togo = {}; // note that fluid.transforms.arrayToObject can't unpack this value
fluid.each(array, function (element, index) {
togo[element.namespace] = - index * 10;
});
return togo;
};

fluid.modelChangedToChange = function (args) {
return {
value: args[0],
Expand Down
18 changes: 11 additions & 7 deletions src/framework/core/js/Fluid.js
Original file line number Diff line number Diff line change
Expand Up @@ -736,8 +736,8 @@ var fluid = fluid || fluid_2_0_0;

/** Converts a hash into an object by hoisting out the object's keys into an array element via the supplied String "key", and then transforming via an optional further function, which receives the signature
* (newElement, oldElement, key) where newElement is the freshly cloned element, oldElement is the original hash's element, and key is the key of the element.
* If the function is not supplied, the old element is simply deep-cloned onto the new element (same effect
* as transform fluid.transforms.objectToArray)
* If the function is not supplied, the old element is simply deep-cloned onto the new element (same effect as transform fluid.transforms.objectToArray).
* The supplied hash will not be modified, unless the supplied function explicitly does so by modifying its 2nd argument.
*/
fluid.hashToArray = function (hash, keyName, func) {
var togo = [];
Expand Down Expand Up @@ -1267,12 +1267,16 @@ var fluid = fluid || fluid_2_0_0;
}
};

fluid.parsePriorityRecords = function (records, name, root) {
/** Parse a hash containing prioritised records (for example, as found in a ContextAwareness record) and return a sorted array of these records in priority order.
* @param records {Object} A hash of key names to prioritised records. Each record may contain an member `namespace` - if it does not, the namespace will be taken from the
* record's key. It may also contain a `String` member `priority` encoding a priority with respect to these namespaces as document at http://docs.fluidproject.org/infusion/development/Priorities.html .
* @param name {String} A human-readable name describing the supplied records, which will be incorporated into the message of any error encountered when resolving the priorities
* @return [Array] An array of the same elements supplied to `records`, sorted into priority order. The supplied argument `records` will not be modified.
*/
fluid.parsePriorityRecords = function (records, name) {
var array = fluid.hashToArray(records, "namespace", function (newElement, oldElement, index) {
if (!root) {
$.extend(newElement, oldElement);
}
newElement.priority = fluid.parsePriority(root ? oldElement : oldElement.priority, index, false, name);
$.extend(newElement, oldElement);
newElement.priority = fluid.parsePriority(oldElement.priority, index, false, name);
});
fluid.sortByPriority(array);
return array;
Expand Down
24 changes: 8 additions & 16 deletions tests/framework-tests/core/js/DataBindingTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -855,21 +855,11 @@ https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
jqUnit.assertDeepEq("Captured model by argument", {x: 30, y: 30}, that.frozenModel.windowHolders.mainWindow);
});

/** FLUID-5866: Global priorities mediated by "priorityHolder" component **/

/** FLUID-5866: Global priorities mediated without "priorityHolder" component **/
fluid.defaults("fluid.tests.fluid5866root", {
gradeNames: "fluid.modelComponent",
components: {
priorityHolder: {
type: "fluid.priorityHolder",
options: {
priorities: {
repaint: null,
notifyExternal: "after:repaint",
compute: "before:repaint"
}
}
},
notifier: {
type: "fluid.modelComponent",
options: {
Expand All @@ -878,7 +868,8 @@ https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
},
modelListeners: {
position: {
priority: "{priorityHolder}.priorities.notifyExternal",
priority: "after:repaint",
namespace: "notifyExternal",
func: "fluid.tests.recordFire",
excludeSource: "init",
args: ["{fluid5866root}", "notifyExternal"]
Expand All @@ -894,7 +885,8 @@ https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
},
modelListeners: {
position: {
priority: "{priorityHolder}.priorities.compute",
namespace: "compute",
priority: "before:repaint",
func: "fluid.tests.recordFire",
excludeSource: "init",
args: ["{fluid5866root}", "compute"]
Expand All @@ -911,15 +903,15 @@ https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
},
modelListeners: {
position: {
priority: "{priorityHolder}.priorities.repaint",
namespace: "repaint",
func: "fluid.tests.recordFire",
excludeSource: "init",
args: ["{that}", "repaint"]
}
}
});

jqUnit.test("FLUID-5866: Global priorities mediated by \"priorityHolder\" component", function () {
jqUnit.test("FLUID-5866: Global priorities mediated without \"priorityHolder\" component", function () {
var that = fluid.tests.fluid5866root();
that.applier.change("position", 20);
jqUnit.assertDeepEq("Global listeners notified in priority order",
Expand Down

0 comments on commit 6b79a75

Please sign in to comment.