Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

augmenter working finally

  • Loading branch information...
commit 05cd34c012def0234b3c9dd4167041d5fddac1d7 1 parent 3b1d514
@substack authored
Showing with 16 additions and 6 deletions.
  1. +2 −1  example/browser.js
  2. +14 −5 index.js
View
3  example/browser.js
@@ -3,8 +3,9 @@ var sock = shoe('/sock');
var rassoc = require('../');
var render = require('./render/hackerspace.js')();
-render.appendTo('#hackerspaces');
render.pipe(sock).pipe(rassoc(render, {
hacker: require('./render/hacker.js')
}));
+
+render.appendTo('#hackerspaces');
View
19 index.js
@@ -6,27 +6,36 @@ module.exports = function (render, types) {
render.on('element', function (elem) {
var key = elem.getAttribute('data-key');
- streams[key] = {};
+ if (!streams[key]) streams[key] = {};
Object.keys(types).forEach(function (k) {
streams[key][k] = types[k]().appendTo(elem);
});
});
var p = parse();
- var meta = {};
+
+ var meta = {}, mkeys = {};
p.on('meta', function (m) {
+ meta = m;
Object.keys(m).forEach(function (key) {
Object.keys(m[key]).forEach(function (k) {
var mk = m[key][k][1];
- if (!meta[mk]) meta[mk] = [];
- meta[mk].push(key);
+ if (!mkeys[mk]) mkeys[mk] = [];
+ mkeys[mk].push(key);
});
});
});
+ p.on('augment', function (row, key, stream) {
+ if (stream.startKeys && stream.endKeys) {
+ var parts = [ stream.startKeys, stream.endKeys ];
+ parts[1][4] = {}; // because undefined turns to null in stringify
+ render.emit('data', JSON.stringify(parts) + '\n');
+ }
+ });
p.pipe(through(function (row) {
var t = row && row.value && row.value.type;
- var keys = t && types[t] && meta[t];
+ var keys = t && mkeys[t];
if (keys) {
keys.forEach(function (key) {
var s = streams[row.value[key]];
Please sign in to comment.
Something went wrong with that request. Please try again.