Permalink
Browse files

groups

  • Loading branch information...
1 parent 18290cb commit 48e6de2d794339a6fdb69b0a40f0cf8ccb45f11d @vogievetsky committed Jun 22, 2012
Showing with 116 additions and 13 deletions.
  1. +27 −5 dvl.coffee
  2. +36 −7 dvl.js
  3. +1 −1 tests/core/block.js
  4. +52 −0 tests/core/group.js
View
@@ -193,7 +193,11 @@ dvl.util = {
return obj
escapeHTML: (str) ->
- return str.replace(/&/g,'&amp;').replace(/>/g,'&gt;').replace(/</g,'&lt;').replace(/"/g,'&quot;')
+ return String(str)
+ .replace(/&/g, '&amp;')
+ .replace(/>/g, '&gt;')
+ .replace(/</g, '&lt;')
+ .replace(/"/g, '&quot;')
}
do ->
@@ -493,6 +497,18 @@ do ->
return block
+ dvl.group = (fn, ctx) -> (fnArgs...) ->
+ return unless dvl.notify is init_notify
+ captured_notifies = []
+ dvl.notify = (args...) ->
+ Array::push.apply(captured_notifies, args)
+ return
+ fn.apply(ctx, fnArgs)
+ dvl.notify = init_notify
+ init_notify.apply(dvl, captured_notifies)
+ return
+
+
dvl.const = (value) -> new DVLConst(value)
dvl.def = (value) -> new DVLDef(value)
@@ -1783,6 +1799,8 @@ do ->
self = dvl.valueOf(parent).append(nodeType)
self.attr('id', staticId) is staticId
self.attr('class', staticClass) is staticClass
+ else
+ staticClass = self.attr('class')
self = dvl.wrapVar(self)
@@ -2372,7 +2390,7 @@ dvl.compare = (acc, reverse, ignoreCase) ->
## parent: Where to append the table.
## ~data: The data displayed.
## classStr: The class to add to the table.
-## ~rowClassGen: The generator for row classes
+## ~rowClass: The generator for row classes
## ~visible: Toggles the visibility of the table. [true]
## columns: A list of columns to drive the table.
## column:
@@ -2415,7 +2433,7 @@ do ->
}
}
- sort = sort or {}
+ sort or= {}
sortOn = dvl.wrapVar(sort.on)
sortDir = dvl.wrapVar(sort.dir)
sortOnIndicator = dvl.wrapVar(sort.onIndicator ? sortOn)
@@ -2433,13 +2451,13 @@ do ->
compareMap[c.id] = comp
compareList.push comp
- if not c.compareModes?[0]
+ if not c.compareModes
c.compareModes = default_compare_modes
headerCol.push {
id: c.id
title: c.title
- class: c.class
+ class: (c.class or '') + (if c.sortable then ' sortable' else '')
visible: c.visible
tooltip: c.headerTooltip
}
@@ -2453,6 +2471,10 @@ do ->
on: c.on
}
+ headerCol.forEach (c) ->
+ c.indicator = dvl.apply([sortOn, sortDir], (so, sd) -> if so is c.id then sd else 'none')
+ return
+
compare = dvl.def(null)
dvl.register {
listen: compareList
View
43 dvl.js

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -17,4 +17,4 @@ var suite = vows.describe("dvl.block");
// });
-suite.export(module);
+suite.export(module);
View
@@ -0,0 +1,52 @@
+var dvl = require("../../dvl");
+
+var vows = require("vows"),
+ assert = require("assert");
+
+var suite = vows.describe("dvl.group");
+
+suite.addBatch({
+ "basic group": {
+ topic: function() {
+ var t = {
+ runs: 0,
+ a: dvl.def(1),
+ b: dvl.def(2),
+ set: function(x) {
+ t.a.value(x)
+ t.b.value(x)
+ }
+ };
+
+ dvl.register({
+ listen: [t.a, t.b],
+ fn: function() {
+ t.runs++;
+ }
+ });
+
+ return t;
+ },
+
+ "no group 2 calls": function(t) {
+ t.runs = 0;
+ t.set(10);
+ assert.strictEqual(t.runs, 2);
+ },
+
+ "with group 1 call": function(t) {
+ t.runs = 0;
+ dvl.group(t.set)(20);
+ assert.strictEqual(t.runs, 1);
+ },
+
+ "with group but same value": function(t) {
+ t.runs = 0;
+ dvl.group(t.set)(20);
+ assert.strictEqual(t.runs, 0);
+ },
+ },
+});
+
+
+suite.export(module);

0 comments on commit 48e6de2

Please sign in to comment.