   if: cond
 
   bind
+
+  # Initial value.
+  init
 }, fn) ->
   # The default value is simply the value of the item.
   val ?= -> @val
 
+  watcher = {
+    # Method allowing the cleanup when the helper is no longer used.
+    cleanUp: -> # TODO: noop for now.
+
+    # Keys of items using the current helper.
+    consumers: Object.create null
+
+    generator: ->
+      {key} = this
+
+      # Register this item has a consumer.
+      watcher.consumers[@key] = true
+
+      # Returns the value for this item if any or the common value.
+      values = watcher.values
+      if key of values
+        values["$#{key}"]
+      else
+        values.common
+
+    # Current values.
+    values: Object.create null
+  }
+  watcher.values.common = init
+
   process = (event, items) ->
-    values = []
+    # Values are grouped by namespace.
+    valuesByNamespace = Object.create null
 
     $_.each items, (item) ->
       return unless not cond? or cond.call item

      else
        'common'

      values.push [event, value, namespace]

    # If something has been processed, call `fn`.
    fn values unless $_.isEmpty values

  processOne = (event, item) ->
    process event, [item]

  # Contrary to other helpers, the default value is the key.
  options.val ?= -> @key

  options.init = []

  watcher = $watch this, options, (entered, exited) ->
    changed = false

    for value in entered
      if @value.indexOf value is -1
        @value.push value
        changed = true

    for value in exited
      changed = true if $removeValue @value, value

    changed

  watcher.generator

#---------------------------------------------------------------------

$sum = (options) ->
  options.init ?= 0

  watcher = $watch this, options, (entered, exited) ->
    prev = @value

    @value += value for value in entered
    @value -= value for value in exited

    @value isnt prev

  watcher.generator

#---------------------------------------------------------------------

# Uses a value from another item.
#
# Important note: Behavior is not specified when binding to multiple
# items.
$val = (options) ->
  # The default value.
  def = options.default
  delete options.default

  options.init ?= def

  # Should the last value be kept instead of returning to the default
  # value when no items are available!
  keepLast = !!options.keepLast
  delete options.keepLast

  watcher = $watch this, options, (entered, exited) ->
    prev = @value

    if not $_.isEmpty entered
      @value = entered[0]
    else
      @value = def unless keepLast

    @value isnt prev

  watcher.generator

#=====================================================================

