raptor-render-context
Advanced tools
Comparing version 0.2.4-beta to 0.2.5-beta
@@ -19,8 +19,5 @@ /* | ||
var logger = require('raptor-logging').logger(module); | ||
var promiseUtil = require('raptor-promises/util'); | ||
var extend = require('raptor-util').extend; | ||
var EventEmitter = require('events').EventEmitter; | ||
var includeStack = false; | ||
var nextUniqueId = 0; | ||
@@ -31,10 +28,2 @@ var voidWriter = { | ||
function StreamWriter(stream) { | ||
this.stream = stream; | ||
} | ||
StreamWriter.prototype.write = function(data) { | ||
this.stream.write(data); | ||
}; | ||
function getAsyncAttributes(context) { | ||
@@ -77,5 +66,2 @@ var attrs = context.attributes; | ||
flush: function () { | ||
if (!this.ready || this.flushed) { | ||
throw new Error('Invalid state'); | ||
} | ||
var writer = this.writer; | ||
@@ -158,6 +144,4 @@ writer.write(this.buffer.toString()); | ||
if (writer.pipe) { | ||
var stream = writer; | ||
writer = new StreamWriter(stream); | ||
this.on('end', function() { | ||
stream.end(); | ||
writer.end(); | ||
}); | ||
@@ -184,5 +168,2 @@ } | ||
}, | ||
uniqueId: function () { | ||
return 'c' + nextUniqueId++; | ||
}, | ||
write: function (str) { | ||
@@ -217,3 +198,3 @@ if (str !== null && str !== undefined) { | ||
}, | ||
beginAsync: function (callback, timeout) { | ||
beginAsync: function (timeout) { | ||
var asyncAttributes = getAsyncAttributes(this); | ||
@@ -235,2 +216,3 @@ // Keep a count of all of the async fragments for this rendering | ||
asyncFragment.next = bufferedFragment; | ||
asyncContext.asyncFragment = asyncFragment; | ||
asyncContext.parentAsyncFragment = asyncFragment; | ||
@@ -263,33 +245,3 @@ var prevAsyncFragment = this.prevAsyncFragment || this.parentAsyncFragment; | ||
try { | ||
var promise = callback(asyncContext, function(err, data) { | ||
if (err) { | ||
return asyncFragment.end(err); | ||
} | ||
if (data) { | ||
asyncContext.write(data); | ||
} | ||
asyncFragment.end(); | ||
}); | ||
// Provide the user with the async context and the async fragment | ||
if (promise) { | ||
promiseUtil.immediateThen( | ||
promise, | ||
function (result) { | ||
if (result != null) { | ||
asyncContext.write(result); | ||
} | ||
asyncFragment.end(); | ||
}, | ||
function (e) { | ||
asyncFragment.end(e); | ||
}); | ||
} | ||
} catch (e) { | ||
asyncFragment.end(e); | ||
} | ||
return this; | ||
return asyncContext; | ||
}, | ||
@@ -323,10 +275,26 @@ on: function(event, callback) { | ||
end: function() { | ||
var async = this.attributes.async; | ||
async.ended = true; | ||
error: function(e) { | ||
if (this.asyncFragment) { | ||
this.asyncFragment.end(e); | ||
} else { | ||
this.emit('error', e); | ||
} | ||
}, | ||
if (async.remaining === 0) { | ||
this.emit('end'); | ||
end: function(data) { | ||
if (data) { | ||
this.write(data); | ||
} | ||
if (this.asyncFragment) { | ||
this.asyncFragment.end(); | ||
} else { | ||
var async = this.attributes.async; | ||
async.ended = true; | ||
if (async.remaining === 0) { | ||
this.emit('end'); | ||
} | ||
} | ||
return this; | ||
@@ -340,6 +308,2 @@ } | ||
if (typeof window === 'undefined') { | ||
extend(Context.prototype, require('./Context' + '_server')); // String concatenation to fool the bundlers | ||
} | ||
module.exports = Context; |
@@ -23,8 +23,6 @@ /* | ||
*/ | ||
'use strict'; | ||
var StringBuilder = require('raptor-strings/StringBuilder'); | ||
var Context = require('./Context'); | ||
exports.create = function (writer) { | ||
return new Context(writer || new StringBuilder()); //Create a new context using the writer provided | ||
return new Context(writer); //Create a new context using the writer provided | ||
}; | ||
@@ -31,0 +29,0 @@ |
@@ -14,6 +14,3 @@ { | ||
"dependencies": { | ||
"raptor-util": "^0.2.0-beta", | ||
"raptor-logging": "^0.2.0-beta", | ||
"raptor-detect": "^0.2.0-beta", | ||
"raptor-promises": "^0.2.0-beta", | ||
"raptor-strings": "^0.2.0-beta", | ||
@@ -36,3 +33,3 @@ "events": "^1.0.0" | ||
}, | ||
"version": "0.2.4-beta" | ||
"version": "0.2.5-beta" | ||
} |
@@ -21,3 +21,3 @@ raptor-render-context | ||
require('raptor-render-context').create(stream); | ||
var context = require('raptor-render-context').create(stream); | ||
.on('error', function(err) { | ||
@@ -29,10 +29,13 @@ // Something went wrong during rendering | ||
}) | ||
.write('A') | ||
.beginAsync(function(context, done) { | ||
setTimeout(function() { | ||
context.write('B'); | ||
}, 1000); | ||
}) | ||
.write('C') | ||
.write('A'); | ||
var asyncContext = context.beginAsync(); | ||
setTimeout(function() { | ||
asyncContext.write('B'); | ||
asyncContext.end(); | ||
}, 1000); | ||
context.write('C') | ||
.end(); | ||
``` | ||
``` |
174
test/test.js
@@ -38,15 +38,17 @@ 'use strict'; | ||
context.write('1'); | ||
context.beginAsync(function(asyncContext, done) { | ||
setTimeout(function() { | ||
asyncContext.write('2'); | ||
done(); | ||
}, 200); | ||
}); | ||
var asyncContext1 = context.beginAsync(); | ||
setTimeout(function() { | ||
asyncContext1.write('2'); | ||
asyncContext1.end(); | ||
}, 100); | ||
context.write('3'); | ||
context.beginAsync(function(asyncContext, done) { | ||
setTimeout(function() { | ||
asyncContext.write('4'); | ||
done(); | ||
}, 10); | ||
}); | ||
var asyncContext2 = context.beginAsync(); | ||
setTimeout(function() { | ||
asyncContext2.write('4'); | ||
asyncContext2.end(); | ||
}, 10); | ||
context.end(); | ||
@@ -63,6 +65,9 @@ context.on('end', function() { | ||
context.write('1'); | ||
context.beginAsync(function(asyncContext, done) { | ||
var asyncContext = context.beginAsync(); | ||
setTimeout(function() { | ||
asyncContext.write('2'); | ||
done(); | ||
}); | ||
asyncContext.end(); | ||
}, 10); | ||
context.write('3'); | ||
@@ -80,7 +85,8 @@ context.end(); | ||
context.write('1'); | ||
context.beginAsync(function(asyncContext, done) { | ||
setTimeout(function() { | ||
done(null, 2); | ||
}, 10); | ||
}); | ||
var asyncContext = context.beginAsync(); | ||
setTimeout(function() { | ||
asyncContext.end('2'); | ||
}, 10); | ||
context.write('3'); | ||
@@ -103,7 +109,9 @@ context.end(); | ||
context.write('1'); | ||
context.beginAsync(function(asyncContext, done) { | ||
setTimeout(function() { | ||
done(null, '2'); | ||
}, 200); | ||
}, 100); | ||
var asyncContext = context.beginAsync(100); | ||
setTimeout(function() { | ||
asyncContext.write('2'); | ||
asyncContext.end(); | ||
}, 200); | ||
context.write('3'); | ||
@@ -122,28 +130,39 @@ context.end(); | ||
context.write('1'); | ||
context.beginAsync(function(asyncContext, done) { | ||
var asyncContext = context.beginAsync(); | ||
setTimeout(function() { | ||
asyncContext.write('2a'); | ||
var nestedAsyncContext = asyncContext.beginAsync(); | ||
setTimeout(function() { | ||
asyncContext.write('2a'); | ||
asyncContext.beginAsync(function(asyncContext, done) { | ||
asyncContext.write('2b'); | ||
done(); | ||
}); | ||
asyncContext.write('2c'); | ||
done(); | ||
}, 30); | ||
}); | ||
nestedAsyncContext.write('2b'); | ||
nestedAsyncContext.end(); | ||
}, 10); | ||
asyncContext.write('2c'); | ||
asyncContext.end(); | ||
}, 10); | ||
context.write('3'); | ||
context.beginAsync(function(asyncContext, done) { | ||
var asyncContext2 = context.beginAsync(); | ||
setTimeout(function() { | ||
var nestedAsyncContext = asyncContext2.beginAsync(); | ||
setTimeout(function() { | ||
asyncContext.beginAsync(function(asyncContext, done) { | ||
asyncContext.write('4a'); | ||
done(); | ||
}); | ||
asyncContext.beginAsync(function(asyncContext, done) { | ||
asyncContext.write('4b'); | ||
done(); | ||
}); | ||
asyncContext.write('4c'); | ||
done(); | ||
}, 30); | ||
}); | ||
nestedAsyncContext.write('4a'); | ||
nestedAsyncContext.end(); | ||
}, 10); | ||
var nestedAsyncContext2 = asyncContext2.beginAsync(); | ||
setTimeout(function() { | ||
nestedAsyncContext2.write('4b'); | ||
nestedAsyncContext2.end(); | ||
}, 10); | ||
asyncContext2.write('4c'); | ||
asyncContext2.end(); | ||
}, 10); | ||
context.end(); | ||
@@ -165,5 +184,7 @@ context.on('end', function() { | ||
context.write('1'); | ||
context.beginAsync(function(asyncContext, done) { | ||
throw new Error('test'); | ||
}); | ||
var asyncContext = context.beginAsync(); | ||
setTimeout(function() { | ||
asyncContext.error(new Error('test')); | ||
}, 10); | ||
context.write('3'); | ||
@@ -191,9 +212,10 @@ context.end(); | ||
}) | ||
.write('1') | ||
.beginAsync(function(asyncContext, done) { | ||
setTimeout(function() { | ||
done(new Error('test')); | ||
}, 10); | ||
}) | ||
.write('3') | ||
.write('1'); | ||
var asyncContext = context.beginAsync(); | ||
setTimeout(function() { | ||
asyncContext.error(new Error('test')); | ||
}, 10); | ||
context.write('3') | ||
.end(); | ||
@@ -212,3 +234,3 @@ }); | ||
var errors = []; | ||
require('../').create(through) | ||
var context = require('../').create(through) | ||
.on('error', function(e) { | ||
@@ -222,9 +244,11 @@ errors.push(e); | ||
}) | ||
.write('1') | ||
.beginAsync(function(asyncContext, done) { | ||
setTimeout(function() { | ||
done(null, '2'); | ||
}, 10); | ||
}) | ||
.write('3') | ||
.write('1'); | ||
var asyncContext = context.beginAsync(); | ||
setTimeout(function() { | ||
asyncContext.write('2'); | ||
asyncContext.end(); | ||
}, 10); | ||
context.write('3') | ||
.end(); | ||
@@ -247,3 +271,3 @@ }); | ||
var errors = []; | ||
require('../').create(out) | ||
var context = require('../').create(out) | ||
.on('error', function(e) { | ||
@@ -254,9 +278,11 @@ errors.push(e); | ||
}) | ||
.write('1') | ||
.beginAsync(function(asyncContext, done) { | ||
setTimeout(function() { | ||
done(null, '2'); | ||
}, 10); | ||
}) | ||
.write('3') | ||
.write('1'); | ||
var asyncContext = context.beginAsync(); | ||
setTimeout(function() { | ||
asyncContext.write('2'); | ||
asyncContext.end(); | ||
}, 10); | ||
context.write('3') | ||
.end(); | ||
@@ -263,0 +289,0 @@ }); |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
3
40
1
22073
8
521
- Removedraptor-detect@^0.2.0-beta
- Removedraptor-promises@^0.2.0-beta
- Removedraptor-util@^0.2.0-beta
- Removedq@0.9.7(transitive)
- Removedraptor-promises@0.2.0-beta(transitive)
- Removedraptor-util@0.2.0-beta(transitive)