Created
September 17, 2012 20:20
-
-
Save notlion/3739541 to your computer and use it in GitHub Desktop.
Derby model/store listener tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Middleware Function | |
expressApp.use(function(req, res, next) { | |
req.getModel().subscribe("*", function(err, model) { | |
model.on("set", "*", function(path, value) { | |
console.log("Middleware - %s: %s", path, value) | |
}) | |
next() | |
}) | |
}) | |
// Prints "Middleware - _$component.6b8c1a9e-35e7-4dc8-bcda-2bd12e8b2fca: [object Object]" | |
// and doesn't fire when client model changes are synced. | |
// Same result with expressApp.get('/', function(req, res)... | |
// store.createModel | |
store.createModel().subscribe("*", function(err, model) { | |
model.on("set", "*", function(path, value, out, isLocal) { | |
console.log("createModel - %s: %s", path, value) | |
if(!isLocal) | |
model.set("result", "hello") | |
}) | |
}) | |
// Works as expected, printing "createModel - <path>: <value>" and sets result to "hello" | |
// However, the model change history is repeated every 10 seconds (console output below) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5e6f3d0d-576a-4997-a712-cdf0983a01fe ↩ Disconnect: booted | |
4c595447-3e12-4c55-834a-1bd2a12f496b ↩ Connect | |
4c595447-3e12-4c55-834a-1bd2a12f496b ↪ Asking client to request a snapshot update of new transactions | |
4c595447-3e12-4c55-834a-1bd2a12f496b ↩ Derby app with hash 7jZswxG7t1BoXEuNbXalEw | |
4c595447-3e12-4c55-834a-1bd2a12f496b ↩ ver: 0 - set 'a', '' | |
createModel - a: | |
4c595447-3e12-4c55-834a-1bd2a12f496b ↪ ver: 2 - set 'result', 'hello' | |
createModel - result: hello | |
Setting. Time since last: 8.413 | |
4c595447-3e12-4c55-834a-1bd2a12f496b ↩ ver: 1 - set 'a', '' | |
createModel - a: | |
4c595447-3e12-4c55-834a-1bd2a12f496b ↪ ver: 4 - set 'result', 'hello' | |
createModel - result: hello | |
Setting. Time since last: 11.079 | |
4c595447-3e12-4c55-834a-1bd2a12f496b ↩ ver: 3 - set 'a', '' | |
createModel - a: | |
4c595447-3e12-4c55-834a-1bd2a12f496b ↪ ver: 6 - set 'result', 'hello' | |
createModel - result: hello | |
Setting. Time since last: 10.005 | |
4c595447-3e12-4c55-834a-1bd2a12f496b ↩ ver: 5 - set 'a', '' | |
createModel - a: | |
4c595447-3e12-4c55-834a-1bd2a12f496b ↪ ver: 8 - set 'result', 'hello' | |
createModel - result: hello | |
Setting. Time since last: 9.999 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment