var øEmit = require('stereo/emit');
var øOn = require('stereo/on');
var øWhen = require('stereo/when');
var attributeUpdater = require('./model/attributeUpdater');

// TODO: Document the function.
module.exports = function model(rootElement) {

  // Initialize the input channel `patches`.
  var patches = Object.freeze({
    emit: øEmit(),
  });

  // Initialize the output channel `updates`.
  var emitUpdates = øEmit();
  var updates = Object.freeze({
    on: øOn(emitUpdates),
    when: øWhen(emitUpdates),
  });
  // TODO: Add `off`.
  var emitCurrentAttributes = attributeUpdater({
    emitter: emitUpdates,
    attributesObject: rootElement.attributes,
  });

  // Emit initial messages to `updates`.
  emitCurrentAttributes();

  // Export channels and `attributeChangedCallback`.
  return Object.freeze({
    patches: patches,
    updates: updates,
    attributeChangedCallback: emitCurrentAttributes,
  });
};

@@ -279,24 +279,53 @@
  %60patches%60.%0A
+  var emitPatches = %C3%B8Emit();%0A
   var patche
@@ -358,16 +358,326 @@
 it: 
-%C3%B8Emit(),
+emitPatches,%0A  %7D);%0A  var onPatches = %C3%B8On(emitPatches);%0A%0A  onPatches('apply', function (patch) %7B%0A    Object.keys(patch).forEach(function(attribute) %7B%0A      var value = patch%5Battribute%5D;%0A      if (value === undefined) rootElement.removeAttribute(attribute);%0A      else rootElement.setAttribute(attribute, value);%0A    %7D);
 %0A  %7D

Implement `model.patches` [#6619]