statebus 6.1.21 → 7.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/extras/tests.js CHANGED
@@ -117,7 +117,7 @@ test(function applying_patches (done) {
117
117
 
118
118
  test(function prune (done) {
119
119
  var boose = require('../statebus')()
120
- boose.save({key: 'nark', _: 333666})
120
+ boose.set({key: 'nark', _: 333666})
121
121
  var a = {key: 'funny',
122
122
  b: {key: 'farty', booger: 3}}
123
123
  assert(!boose.prune(a).b.booger)
@@ -129,22 +129,23 @@ test(function prune (done) {
129
129
 
130
130
  test(function auto_vars (done) {
131
131
  var n = require('../statebus')()
132
- n('r/*').to_fetch = function (rest, o) {return {rest: rest, o: o}}
133
- log(n.fetch('r/3'))
134
- assert(n.fetch('r/3').rest === '3')
135
- assert(n.fetch('r/3').o === undefined)
136
-
137
- n('v/*').to_fetch = function (vars, star) {return {vars: vars, rest: star}}
138
- log(n.fetch('v/[3,9 4]').rest)
139
- log(n.fetch('v/[3,9 4]').rest.match(/$Bad/))
140
- assert(n.fetch('v/[3,9 4]').rest === '[3,9 4]')
141
-
142
- log(n.fetch('v/[3,9 4]').vars)
143
- log(n.fetch('v/[3,9 4]').vars.match(/^Bad/))
144
- assert(n.fetch('v/[3,9 4]').vars.match(/^Bad/))
145
- assert(Array.isArray(n.fetch('v/[3,4]').vars))
146
-
147
- n('a/*').to_save = function (t, k, obj) {
132
+ n('r/*').to_get = function (rest, o) {return {rest, o}}
133
+ log(n.get('r/3'))
134
+ assert(n.get('r/3').rest === '3')
135
+ assert(n.get('r/3').o === undefined,
136
+ 'o is not undefined: ' + JSON.stringify(n.get('r/3')))
137
+
138
+ n('v/*').to_get = function (vars, star) {return {vars: vars, rest: star}}
139
+ log(n.get('v/[3,9 4]').rest)
140
+ log(n.get('v/[3,9 4]').rest.match(/$Bad/))
141
+ assert(n.get('v/[3,9 4]').rest === '[3,9 4]')
142
+
143
+ log(n.get('v/[3,9 4]').vars)
144
+ log(n.get('v/[3,9 4]').vars.match(/^Bad/))
145
+ assert(n.get('v/[3,9 4]').vars.match(/^Bad/))
146
+ assert(Array.isArray(n.get('v/[3,4]').vars))
147
+
148
+ n('a/*').to_set = function (t, k, obj) {
148
149
  log('k:', k, 't:', t, 'o:', obj)
149
150
  assert(k === 'a/foo')
150
151
  assert(typeof obj === 'object')
@@ -154,7 +155,7 @@ test(function auto_vars (done) {
154
155
  t.done()
155
156
  }
156
157
  for (var i=0; i<4; i++)
157
- n.save({key: 'a/foo', i:i})
158
+ n.set({key: 'a/foo', i:i})
158
159
 
159
160
  log('Forgetting things now')
160
161
  n('v/*').to_forget = function (vars, star) {log('(from auto_vars) forgot v/' + star)}
@@ -192,7 +193,7 @@ test(function serve_options (done) {
192
193
  certs: {private_key: certs+'/pk', certificate: certs+'/cert'},
193
194
  })
194
195
 
195
- b.save({key: 'foo', body: 'is this on disk?'})
196
+ b.set({key: 'foo', body: 'is this on disk?'})
196
197
  setTimeout(() => done(), 60)
197
198
  })
198
199
 
@@ -201,47 +202,47 @@ test(function transactions (done) {
201
202
  bus.honk = 'statelog'
202
203
  bus.label = 'tranny'
203
204
 
204
- // Test to_fetch handlers with t.done()
205
- bus('foo1').to_fetch = function (t) {
206
- log('to_fetching foo1')
205
+ // Test to_get handlers with t.done()
206
+ bus('foo1').to_get = function (t) {
207
+ log('to_geting foo1')
207
208
  setTimeout(()=>{
208
209
  log('returning something for foo1')
209
210
  t.done({something: 'yeah'})
210
211
  }, 0)
211
212
  }
212
- var foo1 = bus.fetch('foo1')
213
+ var foo1 = bus.get('foo1')
213
214
  assert(!foo1.something)
214
215
  setTimeout(() => { log('test foo1'); assert(foo1.something === 'yeah') }, 10)
215
216
 
216
217
  // And return a value directly
217
- bus('foo2').to_fetch = (t) => { return {something: 'yeah'} }
218
- var foo2 = bus.fetch('foo2')
218
+ bus('foo2').to_get = (t) => { return {something: 'yeah'} }
219
+ var foo2 = bus.get('foo2')
219
220
  setTimeout(() => { log('test foo2'); assert(foo2.something === 'yeah') }, 10)
220
221
 
221
222
 
222
223
  // Set up some rocks
223
224
  log('Set up some rocks')
224
- bus.save({key: 'rock1', a:1})
225
- bus.save({key: 'rock2', a:1})
226
- bus.save({key: 'softrock1', a:1})
227
- bus.save({key: 'softrock2', a:1})
228
-
229
- // Test to_save handlers with t.done(o), t.abort, 'done', 'abort'
230
- bus('rock1').to_save = (t) => {setTimeout(()=>{ t.abort() }, 0)}
231
- bus('rock2').to_save = ( ) => {return 'abort'}
232
- bus('softrock1').to_save = (t) => {setTimeout(()=>{ t.done() }, 0)}
233
- bus('softrock2').to_save = ( ) => {return 'done'}
225
+ bus.set({key: 'rock1', a:1})
226
+ bus.set({key: 'rock2', a:1})
227
+ bus.set({key: 'softrock1', a:1})
228
+ bus.set({key: 'softrock2', a:1})
229
+
230
+ // Test to_set handlers with t.done(o), t.abort, 'done', 'abort'
231
+ bus('rock1').to_set = (t) => {setTimeout(()=>{ t.abort() }, 0)}
232
+ bus('rock2').to_set = ( ) => {return 'abort'}
233
+ bus('softrock1').to_set = (t) => {setTimeout(()=>{ t.done() }, 0)}
234
+ bus('softrock2').to_set = ( ) => {return 'done'}
234
235
 
235
236
  //bus.honk = true
236
237
  setTimeout(() => {
237
- log('Save some changes')
238
- bus.save({key: 'rock1', a:2})
239
- bus.save({key: 'rock2', a:2})
240
- bus.save({key: 'softrock1', a:2})
241
- bus.save({key: 'softrock2', a:2})
238
+ log('Set some changes')
239
+ bus.set({key: 'rock1', a:2})
240
+ bus.set({key: 'rock2', a:2})
241
+ bus.set({key: 'softrock1', a:2})
242
+ bus.set({key: 'softrock2', a:2})
242
243
 
243
244
  setTimeout(() => {
244
- log('Check if the saves worked...')
245
+ log('Check if the sets worked...')
245
246
  assert(bus.cache.rock1.a == 1)
246
247
  assert(bus.cache.rock2.a == 1)
247
248
  assert(bus.cache.softrock1.a == 2)
@@ -332,14 +333,14 @@ test(function translate_fields (done) {
332
333
  })
333
334
 
334
335
  test(function basics (done) {
335
- bus('basic wait').to_fetch = function () {
336
- setTimeout(function () {bus.save.fire({key:'basic wait', a:1})},
336
+ bus('basic wait').to_get = function () {
337
+ setTimeout(function () {bus.set.fire({key:'basic wait', a:1})},
337
338
  30)
338
339
  }
339
340
 
340
341
  var count = 0
341
342
  bus(function () {
342
- var v = bus.fetch('basic wait')
343
+ var v = bus.get('basic wait')
343
344
  log('On round', count, 'we see', v)
344
345
  if (count == 0)
345
346
  assert(!v.a)
@@ -355,10 +356,10 @@ test(function basics (done) {
355
356
  // Multi-handlers
356
357
  test(function multiple_handlers1 (done) {
357
358
  var cuss = require('../statebus')()
358
- cuss('foo').to_fetch = () => {log('do nothing 1')}
359
- cuss('foo').to_fetch = () => {log('do nothing 2')}
360
- cuss('foo').to_fetch = () => (log('doing something'),{b: 3})
361
- cuss.fetch('foo', (o) => {
359
+ cuss('foo').to_get = () => {log('do nothing 1')}
360
+ cuss('foo').to_get = () => {log('do nothing 2')}
361
+ cuss('foo').to_get = () => (log('doing something'),{b: 3})
362
+ cuss.get('foo', (o) => {
362
363
  log('Multi-handle got', o)
363
364
  cuss.forget()
364
365
  setTimeout(()=>{done()})
@@ -367,44 +368,44 @@ test(function multiple_handlers1 (done) {
367
368
 
368
369
  test(function multiple_handlers2 (done) {
369
370
  var cuss = require('../statebus')()
370
- cuss('foo').to_save = (o) => {log('do nothing 1')}
371
- cuss('foo').to_save = (o) => {log('do nothing 2')}
372
- cuss('foo').to_save = (o) => {log('doin something'); cuss.save.fire(o)}
373
- //cuss('foo').to_save = (o) => {log('doin abortion'); cuss.save.abort(o)}
374
- cuss.save({key: 'foo', b: 55})
371
+ cuss('foo').to_set = (o) => {log('do nothing 1')}
372
+ cuss('foo').to_set = (o) => {log('do nothing 2')}
373
+ cuss('foo').to_set = (o) => {log('doin something'); cuss.set.fire(o)}
374
+ //cuss('foo').to_set = (o) => {log('doin abortion'); cuss.set.abort(o)}
375
+ cuss.set({key: 'foo', b: 55})
375
376
  log('over and out')
376
377
  setTimeout(()=>{done()})
377
378
  })
378
379
 
379
380
  // Callbacks are reactive
380
- test(function fetch_with_callback (done) {
381
+ test(function get_with_callback (done) {
381
382
  var count = 0
382
383
 
383
384
  function bbs() {
384
- return bus.bindings('bar', 'on_save').map(
385
+ return bus.bindings('bar', 'on_set').map(
385
386
  function (f){return bus.funk_name(f)})
386
387
  }
387
388
  function cb (o) {
388
389
  count++
389
- // log(bbs().length + ' bindings in cb before fetch')
390
- var bar = bus.fetch('bar')
390
+ // log(bbs().length + ' bindings in cb before get')
391
+ var bar = bus.get('bar')
391
392
  log('cb called', count, 'times', 'bar is', bar, 'foo is', o)
392
- // log(bbs().length + ' bindings in cb after fetch')
393
+ // log(bbs().length + ' bindings in cb after get')
393
394
  }
394
395
 
395
396
  // log(bbs().length+ ' bindings to start')
396
397
 
397
- // Fetch a foo
398
- bus.fetch('foo', cb) // Call 1
398
+ // Get a foo
399
+ bus.get('foo', cb) // Call 1
399
400
 
400
401
  // Fire a foo
401
402
  setTimeout(function () {
402
403
  assert(count === 1, '1!=' + count)
403
- // log(bbs().length + ' bindings after first fetch')
404
+ // log(bbs().length + ' bindings after first get')
404
405
 
405
406
  log('firing a new foo')
406
407
  // log(bbs().length + ' bindings')
407
- bus.save.fire({key: 'foo', count:count}) // Call 2
408
+ bus.set.fire({key: 'foo', count:count}) // Call 2
408
409
  }, 30)
409
410
 
410
411
  // Fire a bar, which the callback depends on
@@ -413,9 +414,9 @@ test(function fetch_with_callback (done) {
413
414
  // log(bbs().length+ ' bindings')
414
415
  assert(count === 2, '2!=' + count)
415
416
  bus.honk = true
416
- bus.save.fire({key: 'bar', count:count}) // Call 3
417
+ bus.set.fire({key: 'bar', count:count}) // Call 3
417
418
  log('fired the new bar')
418
- //log(bus.bindings('bar', 'on_save'))
419
+ //log(bus.bindings('bar', 'on_set'))
419
420
  }, 50)
420
421
 
421
422
  // Done
@@ -427,57 +428,57 @@ test(function fetch_with_callback (done) {
427
428
  }, 100)
428
429
  })
429
430
 
430
- test(function fetch_once (done) {
431
+ test(function get_once (done) {
431
432
  var calls = 0
432
- bus.fetch('fetch_once', function cb (o) {
433
+ bus.get('get_once', function cb (o) {
433
434
  calls++
434
- log('Fetch_once called', calls)
435
- assert(calls < 2, 'Fetch-once called twice')
436
- bus.forget('fetch_once', cb)
435
+ log('Get_once called', calls)
436
+ assert(calls < 2, 'Get-once called twice')
437
+ bus.forget('get_once', cb)
437
438
  })
438
- bus.save.fire({key: 'fetch_once', _: 0})
439
- setTimeout(()=> { bus.save.fire({key: 'fetch_once', _: 1}) }, 10)
440
- setTimeout(()=> { bus.save.fire({key: 'fetch_once', _: 2}) }, 20)
439
+ bus.set.fire({key: 'get_once', _: 0})
440
+ setTimeout(()=> { bus.set.fire({key: 'get_once', _: 1}) }, 10)
441
+ setTimeout(()=> { bus.set.fire({key: 'get_once', _: 2}) }, 20)
441
442
  setTimeout(()=> { done() }, 30 )
442
443
  })
443
444
 
444
445
  test(function once (done) {
445
- bus('takeawhile').to_fetch = (t) => {
446
+ bus('takeawhile').to_get = (t) => {
446
447
  setTimeout(_=> t.return({_: 3}), 150)
447
448
  }
448
449
  bus.once(_=> {
449
- var x = bus.fetch('takeawhile')
450
- var y = bus.fetch('changing')
450
+ var x = bus.get('takeawhile')
451
+ var y = bus.get('changing')
451
452
  log('running the once func! loading is', bus.loading())
452
453
  assert(!bus.cache.certified)
453
- bus.save({key: 'whendone', certified: true})
454
+ bus.set({key: 'whendone', certified: true})
454
455
  })
455
456
 
456
- delay(50, _=> assert(!bus.fetch('whendone').certified))
457
- delay(10, _=> bus.save({key: 'changing', _: 1}))
458
- delay(10, _=> bus.save({key: 'changing', _: 2}))
459
- delay(150, _=> assert(bus.fetch('whendone').certified))
460
- delay(10, _=> bus.save({key: 'changing', _: 3}))
461
- delay(10, _=> bus.save({key: 'changing', _: 4}))
457
+ delay(50, _=> assert(!bus.get('whendone').certified))
458
+ delay(10, _=> bus.set({key: 'changing', _: 1}))
459
+ delay(10, _=> bus.set({key: 'changing', _: 2}))
460
+ delay(150, _=> assert(bus.get('whendone').certified))
461
+ delay(10, _=> bus.set({key: 'changing', _: 3}))
462
+ delay(10, _=> bus.set({key: 'changing', _: 4}))
462
463
  delay(30, _=> done())
463
464
  })
464
465
 
465
- // If there's an on_fetch handler, the callback doesn't return
466
+ // If there's an on_get handler, the callback doesn't return
466
467
  // until the handler fires a value
467
- test(function fetch_remote (done) {
468
+ test(function get_remote (done) {
468
469
  var count = 0
469
470
 
470
471
  // The moon responds in 30ms
471
- bus('moon').to_fetch =
472
- function (k) { setTimeout(function () {bus.save.fire({key:k})},30) }
472
+ bus('moon').to_get =
473
+ function (k) { setTimeout(function () {bus.set.fire({key:k})},30) }
473
474
  function cb (o) {
474
475
  count++
475
- var moon = bus.fetch('hey over there')
476
+ var moon = bus.get('hey over there')
476
477
  log('cb called', count, 'times')
477
478
  }
478
479
 
479
- // Fetch a moon
480
- bus.fetch('moon', cb) // Doesn't call back yet
480
+ // Get a moon
481
+ bus.get('moon', cb) // Doesn't call back yet
481
482
  assert(count === 0, '0!=' + count)
482
483
 
483
484
  // There should be a moonshot by now
@@ -500,17 +501,17 @@ test(function duplicate_fires (done) {
500
501
  log('cb called', count, 'times with', calls)
501
502
  }
502
503
 
503
- // Fetch a foo
504
- bus.fetch('foo', cb) // Call 1
504
+ // Get a foo
505
+ bus.get('foo', cb) // Call 1
505
506
  assert(count === 1, '1!=' + count)
506
507
 
507
508
  // Fire a foo
508
509
  setTimeout(function () {
509
510
  log('Firing a few new foos')
510
- bus.save.fire({key: 'foo', n:0}) // Skipped
511
- bus.save.fire({key: 'foo', n:1}) // Skipped
512
- bus.save.fire({key: 'foo', n:2}) // Skipped
513
- bus.save.fire({key: 'foo', n:3}) // Call 2
511
+ bus.set.fire({key: 'foo', n:0}) // Skipped
512
+ bus.set.fire({key: 'foo', n:1}) // Skipped
513
+ bus.set.fire({key: 'foo', n:2}) // Skipped
514
+ bus.set.fire({key: 'foo', n:3}) // Call 2
514
515
  log("ok, now let's see what happens.")
515
516
  }, 30)
516
517
 
@@ -529,23 +530,23 @@ test(function duplicate_fires (done) {
529
530
  test(function identity (done) {
530
531
  var key = 'kooder'
531
532
  var count = 0
532
- function fire () { bus.save.fire({key: 'kooder', count: count}) }
533
- bus(key).to_fetch = function () { setTimeout(fire, 10) }
533
+ function fire () { bus.set.fire({key: 'kooder', count: count}) }
534
+ bus(key).to_get = function () { setTimeout(fire, 10) }
534
535
  function cb() {
535
536
  count++
536
537
  log('cb called', count, 'times')
537
- bus.save.fire(bus.fetch('new'))
538
+ bus.set.fire(bus.get('new'))
538
539
  }
539
- bus.fetch(key, cb)
540
+ bus.get(key, cb)
540
541
 
541
542
  // Done
542
543
  setTimeout(function () {
543
544
  // Calls:
544
545
  // 1. Initial call
545
- // 2. First return from pending fetch
546
+ // 2. First return from pending get
546
547
  assert(count === 1, 'cb called '+count+'!=1 times')
547
548
  bus.forget(key, cb)
548
- bus(key).to_fetch.delete(fire)
549
+ bus(key).to_get.delete(fire)
549
550
  done()
550
551
  }, 40)
551
552
  })
@@ -555,8 +556,8 @@ test(function identity (done) {
555
556
  test(function forgetting (done) {
556
557
  var key = 'kooder'
557
558
  var count = 0
558
- function fire () { log('firing!'); bus.save.fire({key: key, count: count}) }
559
- bus(key).to_fetch = function () { setTimeout(fire, 10) }
559
+ function fire () { log('firing!'); bus.set.fire({key: key, count: count}) }
560
+ bus(key).to_get = function () { setTimeout(fire, 10) }
560
561
 
561
562
  function cb (o) {
562
563
  count++
@@ -570,34 +571,34 @@ test(function forgetting (done) {
570
571
  }
571
572
  }
572
573
 
573
- bus.fetch(key, cb)
574
+ bus.get(key, cb)
574
575
  setTimeout(fire, 70)
575
576
  setTimeout(fire, 80)
576
577
 
577
578
  // Done
578
579
  setTimeout(function () {
579
580
  assert(count === 2, "Count should be 2 but is", count)
580
- bus(key).to_fetch.delete(fire)
581
+ bus(key).to_get.delete(fire)
581
582
  done()
582
583
  }, 100)
583
584
  })
584
585
 
585
- // Can we return an object that fetches another?
586
- test(function nested_fetch (done) {
587
- function outer () { return {inner: bus.fetch('inner') } }
588
- bus('outer').to_fetch = outer
589
- log('fetching the outer wrapper')
590
- var obj = bus.fetch('outer')
591
- log('Ok, we fetched:', obj)
586
+ // Can we return an object that getes another?
587
+ test(function nested_get (done) {
588
+ function outer () { return {inner: bus.get('inner') } }
589
+ bus('outer').to_get = outer
590
+ log('geting the outer wrapper')
591
+ var obj = bus.get('outer')
592
+ log('Ok, we geted:', obj)
592
593
  assert(obj.inner.key === 'inner')
593
- bus.save({key: 'inner', c: 1})
594
+ bus.set({key: 'inner', c: 1})
594
595
  assert(obj.inner.c === 1)
595
596
 
596
- log('vvv Grey line follows (cause outer fetched inner) vvv')
597
+ log('vvv Grey line follows (cause outer geted inner) vvv')
597
598
 
598
599
  // Done
599
600
  setTimeout(function () {
600
- bus('outer').to_fetch.delete(outer)
601
+ bus('outer').to_get.delete(outer)
601
602
  done()
602
603
  }, 10)
603
604
  })
@@ -605,41 +606,41 @@ test(function nested_fetch (done) {
605
606
  // Russian dolls
606
607
  test(function russian_doll_nesting (done) {
607
608
  var nothing = 3
608
- function big () { return {middle: bus.fetch('middle') } }
609
- function middle () { return {small: bus.fetch('small') } }
609
+ function big () { return {middle: bus.get('middle') } }
610
+ function middle () { return {small: bus.get('small') } }
610
611
  function small () { return {nothing: nothing} }
611
- bus('big').to_fetch = big
612
- bus('middle').to_fetch = middle
613
- bus('small').to_fetch = small
612
+ bus('big').to_get = big
613
+ bus('middle').to_get = middle
614
+ bus('small').to_get = small
614
615
 
615
- log('fetching')
616
- var obj = bus.fetch('big')
616
+ log('geting')
617
+ var obj = bus.get('big')
617
618
  log('we got', obj)
618
619
 
619
620
  setTimeout(function () {
620
- bus.fetch('big', function (o) {
621
+ bus.get('big', function (o) {
621
622
  nothing = 5
622
623
  log('About to update small')
623
- bus.save.fire({key: 'small', something: nothing})
624
+ bus.set.fire({key: 'small', something: nothing})
624
625
  log('We did it.')
625
626
  })}, 10)
626
627
 
627
628
  setTimeout(function () {
628
- bus.fetch('big', function ruskie (o) {
629
+ bus.get('big', function ruskie (o) {
629
630
  nothing = 50
630
- var small = bus.fetch('small')
631
+ var small = bus.get('small')
631
632
  log()
632
633
  log('Second try. Small starts as', small)
633
- bus.save.fire({key: 'small', something: nothing})
634
- log('Now it is', bus.fetch('small'))
634
+ bus.set.fire({key: 'small', something: nothing})
635
+ log('Now it is', bus.get('small'))
635
636
  })}, 15)
636
637
 
637
638
 
638
639
  // Done
639
640
  setTimeout(function () {
640
- bus('big').to_fetch.delete(big)
641
- bus('middle').to_fetch.delete(middle)
642
- bus('small').to_fetch.delete(small)
641
+ bus('big').to_get.delete(big)
642
+ bus('middle').to_get.delete(middle)
643
+ bus('small').to_get.delete(small)
643
644
  done()
644
645
  }, 50)
645
646
  })
@@ -647,12 +648,12 @@ test(function russian_doll_nesting (done) {
647
648
  test(function some_handlers_suicide (done) {
648
649
  // These handlers stop reacting after they successfully complete:
649
650
  //
650
- // .on_save
651
- // .to_save
651
+ // .on_set
652
+ // .to_set
652
653
  // .to_forget
653
654
  // .to_delete
654
655
  //
655
- // Ok, that's everyting except for a .to_fetch handler, which
656
+ // Ok, that's everyting except for a .to_get handler, which
656
657
  // runs until its key has been forget()ed.
657
658
 
658
659
  // XXX todo
@@ -750,130 +751,9 @@ test(function readfile (done) {
750
751
  delay(200, () => {done()})
751
752
  })
752
753
 
753
- test(function proxies (done) {
754
- var bus = require('../statebus')()
755
- db = bus.sb
756
- db.foo.a = 3
757
- assert(db.foo.a == 3)
758
- db.foo.a = [1,3,5, 'hello']
759
- db.foo.a.push({key: 'bar', 4:4})
760
-
761
- // Todo: make sure that push() and splice() etc. trigger updates to
762
- // state properly. They should trigger save() when they modify the
763
- // array, and not when they don't.
764
-
765
- log('Now foo is', db.foo)
766
- log('And bar is', db.bar)
767
754
 
768
- db.f = 3
769
- assert(bus.validate(bus.cache['f'], {key: 'f', _: 3}),
770
- bus.cache['f'], 'should be', {key: 'f', _: 3})
771
- assert(db.f === 3)
772
-
773
- db.g = [1,2,4,5]
774
- assert(bus.cache['g']._.length = 4)
775
-
776
- done()
777
- })
778
-
779
- test(function proxies2 (done) {
780
- var bus = require('../statebus')()
781
- var state = bus.state
782
-
783
- assert(state.array === undefined)
784
- assert(state.bar === undefined)
785
-
786
- state.array = []
787
- log('array:', state.array)
788
- assert(state.array.length === 0)
789
- state.array[0] = 1
790
- log('array:', state.array)
791
- assert(state.array.length === 1)
792
- state.bar = {}
793
- log('bar:', state.bar)
794
- state.bar = {a: 1}
795
- log('bar:', state.bar)
796
- assert(state.bar.a === 1)
797
- state.bar.a = state.array
798
- log('bar:', state.bar)
799
- state.array[1] = 2
800
- log('array:', state.array)
801
- log('bar:', state.bar)
802
- assert(state.bar.a[1] === 2,
803
- "Array ref didn't link.\n\t"
804
- + JSON.stringify(bus.cache.bar) + '\n\t'
805
- + JSON.stringify(bus.cache.array))
806
-
807
- state.undefining = undefined
808
- assert(state.undefining === undefined)
809
- state.undefining = {a: undefined}
810
- log('state.undefining =', state.undefining)
811
- // assert(state.undefining.a === undefined)
812
- // TODO: fix https://github.com/invisible-college/statebus/issues/34
813
- state.undefining = {}
814
- assert(!('a' in state.undefining))
815
- state.undefining.a = undefined
816
- assert('a' in state.undefining)
817
- assert(state.undefining.a === undefined)
818
-
819
- state.b = {a: undefined}
820
- assert('a' in state.b)
821
- assert(state.b.a === undefined)
822
- delete state.b.a
823
- // TODO: https://github.com/invisible-college/statebus/issues/34
824
- assert(!('a' in state.b))
825
- assert(state.b.a === undefined)
826
-
827
- return done()
828
-
829
- /*
830
- Things I want to test:
831
-
832
- - Setting nested items
833
- - Escaping their fields
834
- - Calling fetch on them
835
- - Converting state[..] to keyed objects internally
836
- - has() potentially doing a fetch, or loading()
837
- - set() returning a proxy object
838
- - console output
839
- - node AND chrome
840
- - having nice colors and distinctions and shit
841
- */
842
-
843
- state.foo = 3
844
- // This should set into _
845
- console.assert(bus.validate(bus.cache.foo,
846
- {key: 'foo', _: 3}))
847
-
848
-
849
- state.foo = {a: 5}
850
- // This should set directly on it
851
- console.assert(bus.validate(bus.cache.foo,
852
- {key: 'foo', a: 5}))
853
- state.foo.b = 6
854
- console.assert(bus.validate(bus.cache.foo,
855
- {key: 'foo', b: 6}))
856
-
857
- state.bar = [3]
858
- state.foo = {a: 3, bar: state.bar}
859
-
860
- bus(() => {
861
- state.foo // foo triggers re-render
862
- state.foo.bar // bar triggers re-render
863
- state.foo.a // triggers re-render too
864
- })
865
-
866
- // Getting a linked item should do a fetch
867
- bus(() => {
868
- state.bar
869
- })
870
-
871
- // Getting a normal property should do a fetch
872
- })
873
-
874
- test(function braid_proxies (done) {
875
- var bus = require('../statebus').serve({braid_mode: true,
876
- file_store: false})
755
+ test(function proxies (done) {
756
+ var bus = require('../statebus').serve({file_store: false})
877
757
  var state = bus.state
878
758
 
879
759
  assert(state.array === undefined)
@@ -927,9 +807,9 @@ test(function braid_proxies (done) {
927
807
 
928
808
  - Setting nested items
929
809
  - Escaping their fields
930
- - Calling fetch on them
810
+ - Calling get on them
931
811
  - Converting state[..] to keyed objects internally
932
- - has() potentially doing a fetch, or loading()
812
+ - has() potentially doing a get, or loading()
933
813
  - set() returning a proxy object
934
814
  - console output
935
815
  - node AND chrome
@@ -959,53 +839,53 @@ test(function braid_proxies (done) {
959
839
  state.foo.a // triggers re-render too
960
840
  })
961
841
 
962
- // Getting a linked item should do a fetch
842
+ // Getting a linked item should do a get
963
843
  bus(() => {
964
844
  state.bar
965
845
  })
966
846
 
967
- // Getting a normal property should do a fetch
847
+ // Getting a normal property should do a get
968
848
  })
969
849
 
970
850
  test(function only_one (done) {
971
- bus('only_one/*').to_fetch = function (k) {
851
+ bus('only_one/*').to_get = function (k) {
972
852
  var id = k[k.length-1]
973
- return {selected: bus.fetch('selector').choice == id}
853
+ return {selected: bus.get('selector').choice == id}
974
854
  }
975
855
 
976
- assert(!bus.fetch('only_one/1').selected)
977
- assert(!bus.fetch('only_one/2').selected)
978
- assert(!bus.fetch('only_one/3').selected)
856
+ assert(!bus.get('only_one/1').selected)
857
+ assert(!bus.get('only_one/2').selected)
858
+ assert(!bus.get('only_one/3').selected)
979
859
 
980
- bus.save({key: 'selector', choice: 1})
860
+ bus.set({key: 'selector', choice: 1})
981
861
 
982
862
  setTimeout(function () {
983
- assert( bus.fetch('only_one/1').selected)
984
- assert(!bus.fetch('only_one/2').selected)
985
- assert(!bus.fetch('only_one/3').selected)
863
+ assert( bus.get('only_one/1').selected)
864
+ assert(!bus.get('only_one/2').selected)
865
+ assert(!bus.get('only_one/3').selected)
986
866
 
987
- bus.save({key: 'selector', choice: 2})
867
+ bus.set({key: 'selector', choice: 2})
988
868
  }, 10)
989
869
 
990
870
  setTimeout(function () {
991
- assert(!bus.fetch('only_one/1').selected)
992
- assert( bus.fetch('only_one/2').selected)
993
- assert(!bus.fetch('only_one/3').selected)
871
+ assert(!bus.get('only_one/1').selected)
872
+ assert( bus.get('only_one/2').selected)
873
+ assert(!bus.get('only_one/3').selected)
994
874
 
995
- bus.save({key: 'selector', choice: 3})
875
+ bus.set({key: 'selector', choice: 3})
996
876
  }, 20)
997
877
 
998
878
  setTimeout(function () {
999
- assert(!bus.fetch('only_one/1').selected)
1000
- assert(!bus.fetch('only_one/2').selected)
1001
- assert( bus.fetch('only_one/3').selected)
879
+ assert(!bus.get('only_one/1').selected)
880
+ assert(!bus.get('only_one/2').selected)
881
+ assert( bus.get('only_one/3').selected)
1002
882
  done()
1003
883
  }, 30)
1004
884
  })
1005
885
 
1006
- test(function save_can_trigger_tofetch (done) {
886
+ test(function set_can_trigger_toget (done) {
1007
887
  // bus.honk = true
1008
- bus('save_trigger_tofetch').to_fetch =
888
+ bus('set_trigger_toget').to_get =
1009
889
  function (k, old) {
1010
890
  old.yes = Math.random()
1011
891
  return old
@@ -1014,23 +894,23 @@ test(function save_can_trigger_tofetch (done) {
1014
894
  var obj
1015
895
  var triggered = 0
1016
896
  bus(() => {
1017
- log('Aight! Fetching save_trigger_fetch')
1018
- obj = bus.fetch('save_trigger_tofetch')
897
+ log('Aight! Getting set_trigger_get')
898
+ obj = bus.get('set_trigger_toget')
1019
899
  if (bus.loading()) return
1020
900
  triggered++
1021
901
  log('Triggered', triggered, 'times', obj)
1022
902
 
1023
- // XXX todo: because of a bug in how to_fetch is handled, this triggers 4 times instead of 3
903
+ // XXX todo: because of a bug in how to_get is handled, this triggers 4 times instead of 3
1024
904
  assert(triggered <= 4)
1025
905
  log('GGGGGGGGGGGG')
1026
906
  })
1027
907
 
1028
- delay(30, () => { log('savin 1!'); obj.a = 1; bus.save(obj) })
1029
- delay(30, () => { log('savin 2!'); obj.a = 2; bus.save(obj) })
908
+ delay(30, () => { log('savin 1!'); obj.a = 1; bus.set(obj) })
909
+ delay(30, () => { log('savin 2!'); obj.a = 2; bus.set(obj) })
1030
910
  delay(30, done)
1031
911
  })
1032
912
 
1033
- test(function rollback_savefire (done) {
913
+ test(function rollback_setfire (done) {
1034
914
  var count = 0
1035
915
  var error = false
1036
916
  var phase = 0
@@ -1038,23 +918,23 @@ test(function rollback_savefire (done) {
1038
918
  function wait () { setTimeout(function () {
1039
919
  assert(phase++ === 1)
1040
920
  log('Firing wait')
1041
- bus.save.fire({key: 'wait', count: count})
921
+ bus.set.fire({key: 'wait', count: count})
1042
922
  }, 50) }
1043
- bus('wait').to_fetch = wait
923
+ bus('wait').to_get = wait
1044
924
 
1045
925
  // Initialize
1046
- bus.save.fire({key: 'undo me', state: 'start'})
926
+ bus.set.fire({key: 'undo me', state: 'start'})
1047
927
 
1048
928
  // Now start the reactive function
1049
929
  bus(function () {
1050
930
  log('Reaction', ++count, 'starting with state',
1051
- bus.fetch('undo me').state, 'and loading =', bus.loading())
931
+ bus.get('undo me').state, 'and loading =', bus.loading())
1052
932
 
1053
- // Fetch something that we have to wait for
1054
- var wait = bus.fetch('wait')
933
+ // Get something that we have to wait for
934
+ var wait = bus.get('wait')
1055
935
 
1056
- // Save some middling state
1057
- bus.save.fire({key: 'undo me', state: 'progressing'})
936
+ // Set some middling state
937
+ bus.set.fire({key: 'undo me', state: 'progressing'})
1058
938
 
1059
939
  if (count === 1 && !bus.loading()) {
1060
940
  log('### Error! We should be loading!')
@@ -1085,20 +965,20 @@ test(function rollback_savefire (done) {
1085
965
  60)
1086
966
 
1087
967
  setTimeout(function () {
1088
- bus('wait').to_fetch.delete(wait)
968
+ bus('wait').to_get.delete(wait)
1089
969
  assert(phase === 3)
1090
970
  done()
1091
971
  }, 80)
1092
972
  })
1093
973
 
1094
974
  test(function rollback_del (done) {
1095
- bus('wait forever').to_fetch = function () {} // shooting blanks
1096
- bus.save.fire({key: 'kill me', alive: true})
975
+ bus('wait forever').to_get = function () {} // shooting blanks
976
+ bus.set.fire({key: 'kill me', alive: true})
1097
977
 
1098
978
  // First do a del that will roll back
1099
979
  bus(function () {
1100
980
  log('Doing a rollback on', bus.cache['kill me'])
1101
- bus.fetch('wait forever') // Never finishes loading
981
+ bus.get('wait forever') // Never finishes loading
1102
982
  bus.del('kill me') // Will roll back
1103
983
  })
1104
984
  assert(bus.cache['kill me'].alive === true)
@@ -1113,46 +993,46 @@ test(function rollback_del (done) {
1113
993
  done()
1114
994
  })
1115
995
 
1116
- test(function rollback_save (done) {
1117
- var saves = []
996
+ test(function rollback_set (done) {
997
+ var sets = []
1118
998
  var all_done = false
1119
- bus('candy').to_save = function (o) {saves.push(o); bus.save.fire(o)}
1120
- bus.save.fire({key: 'candy', flavor: 'lemon'})
999
+ bus('candy').to_set = function (o) {sets.push(o); bus.set.fire(o)}
1000
+ bus.set.fire({key: 'candy', flavor: 'lemon'})
1121
1001
 
1122
1002
  log('Trying some rollbacks starting with', bus.cache['candy'])
1123
1003
 
1124
- // First do a save that will roll back
1004
+ // First do a set that will roll back
1125
1005
  bus(function () { if (all_done) return;
1126
1006
  log('Doing a rollback on bananafied candy')
1127
- bus.fetch('wait forever') // Never finishes loading
1128
- bus.save({key:'candy', flavor: 'banana'}) // Will roll back
1007
+ bus.get('wait forever') // Never finishes loading
1008
+ bus.set({key:'candy', flavor: 'banana'}) // Will roll back
1129
1009
  log('...and the candy is', bus.cache['candy'])
1130
1010
  //forget('candy')
1131
1011
  })
1132
1012
  assert(bus.cache['candy'].flavor === 'lemon')
1133
- assert(saves.length === 0)
1013
+ assert(sets.length === 0)
1134
1014
 
1135
- // Try rolling back another style of save
1015
+ // Try rolling back another style of set
1136
1016
  bus(function () { if (all_done) return
1137
1017
  log("Now we'll First we licoricize the", bus.cache['candy'])
1138
- bus.fetch('wait forever') // Never finishes loading
1139
- var candy = bus.fetch('candy')
1018
+ bus.get('wait forever') // Never finishes loading
1019
+ var candy = bus.get('candy')
1140
1020
  candy.flavor = 'licorice'
1141
1021
  log('...the candy has become', bus.cache['candy'])
1142
- bus.save(candy) // Will roll back
1022
+ bus.set(candy) // Will roll back
1143
1023
  log('...and now it\'s rolled back to', bus.cache['candy'])
1144
1024
  bus.forget('candy')
1145
1025
  })
1146
1026
  assert(bus.cache['candy'].flavor === 'lemon')
1147
- assert(saves.length === 0)
1027
+ assert(sets.length === 0)
1148
1028
 
1149
- // Now a save that goes through
1029
+ // Now a set that goes through
1150
1030
  bus(function () {
1151
- log('Doing a real save on', bus.cache['candy'])
1152
- bus.save({key:'candy', flavor: 'orangina'}) // Will go through
1031
+ log('Doing a real set on', bus.cache['candy'])
1032
+ bus.set({key:'candy', flavor: 'orangina'}) // Will go through
1153
1033
  })
1154
1034
  assert(bus.cache['candy'].flavor = 'orangina')
1155
- assert(saves.length === 1, 'Saves.length 1 != '+saves.length)
1035
+ assert(sets.length === 1, 'Sets.length 1 != '+sets.length)
1156
1036
 
1157
1037
  log('Now candy is', bus.cache['candy'])
1158
1038
  all_done = true
@@ -1161,11 +1041,11 @@ test(function rollback_save (done) {
1161
1041
 
1162
1042
  test(function rollback_abort (done) {
1163
1043
  var bus = require('../statebus')()
1164
- bus('foo').to_save = (o, t) => {t.abort()}
1044
+ bus('foo').to_set = (o, t) => {t.abort()}
1165
1045
  bus(()=> {
1166
- var o = bus.fetch('foo')
1046
+ var o = bus.get('foo')
1167
1047
  o.bar = 3
1168
- bus.save(o)
1048
+ bus.set(o)
1169
1049
  })
1170
1050
  setTimeout(() => {
1171
1051
  assert(!bus.cache.foo.bar)
@@ -1175,11 +1055,11 @@ test(function rollback_abort (done) {
1175
1055
 
1176
1056
  test(function loading_quirk (done) {
1177
1057
  // Make sure a function that called loading() gets re-run even
1178
- // if the return from a fetch didn't actually change state
1058
+ // if the return from a get didn't actually change state
1179
1059
 
1180
- // First define a delayed save.fire
1181
- bus('wait a sec').to_fetch = function (k) {
1182
- setTimeout(function () { bus.save.fire({key: k}) }, 50)
1060
+ // First define a delayed set.fire
1061
+ bus('wait a sec').to_get = function (k) {
1062
+ setTimeout(function () { bus.set.fire({key: k}) }, 50)
1183
1063
  }
1184
1064
 
1185
1065
  // Now run the test
@@ -1188,7 +1068,7 @@ test(function loading_quirk (done) {
1188
1068
  bus(function () {
1189
1069
  num_calls++
1190
1070
  log('called', num_calls, 'times')
1191
- bus.fetch('wait a sec')
1071
+ bus.get('wait a sec')
1192
1072
  loaded = !bus.loading()
1193
1073
  })
1194
1074
 
@@ -1217,15 +1097,15 @@ test(function default_route (done) {
1217
1097
  var b1 = require('../statebus')()
1218
1098
  var b2 = require('../statebus')()
1219
1099
  b1.shadows(b2)
1220
- b2.save({key: 'foo', bar: 3})
1221
- console.assert(b1.fetch('foo').bar)
1222
- log(b1.fetch('foo'))
1223
- log(b2.fetch('foo'))
1100
+ b2.set({key: 'foo', bar: 3})
1101
+ console.assert(b1.get('foo').bar)
1102
+ log(b1.get('foo'))
1103
+ log(b2.get('foo'))
1224
1104
  b1.delete('foo')
1225
- log(b1.fetch('foo'))
1226
- log(b2.fetch('foo'))
1227
- console.assert(!b1.fetch('foo').bar)
1228
- console.assert(!b2.fetch('foo').bar)
1105
+ log(b1.get('foo'))
1106
+ log(b2.get('foo'))
1107
+ console.assert(!b1.get('foo').bar)
1108
+ console.assert(!b2.get('foo').bar)
1229
1109
  done()
1230
1110
  })
1231
1111
 
@@ -1235,13 +1115,13 @@ function setup_servers () {
1235
1115
  s = require('../statebus').serve({port, file_store: false})
1236
1116
  s.label = 's'
1237
1117
  log('Saving /far on server')
1238
- s.save({key: 'far', away:'is this'})
1118
+ s.set({key: 'far', away:'is this'})
1239
1119
 
1240
1120
  c = require('../statebus')()
1241
1121
  c.label = 'c'
1242
- c.net_mount('/*', 'statei://localhost:' + port)
1122
+ c.ws_mount('/*', 'statei://localhost:' + port)
1243
1123
 
1244
- s.save({key: 'users',
1124
+ s.set({key: 'users',
1245
1125
  all: [ { key: 'user/1',
1246
1126
  name: 'mike',
1247
1127
  email: 'toomim@gmail.com',
@@ -1271,11 +1151,11 @@ test(function setup_server (done) {
1271
1151
  // c.honk = true
1272
1152
 
1273
1153
  setTimeout(function () {
1274
- log('Fetching /far on client')
1154
+ log('Getting /far on client')
1275
1155
  var count = 0
1276
- c.fetch('/far', function (o) {
1156
+ c.get('/far', function (o) {
1277
1157
  log('cb !!!!!!!!! --- ^_^')
1278
- c.fetch('/far')
1158
+ c.get('/far')
1279
1159
  if (o.away === 'is this') {
1280
1160
  log('We got '+o.key+' from the server!')
1281
1161
 
@@ -1300,11 +1180,11 @@ test(function login (done) {
1300
1180
 
1301
1181
  //c.honk = true
1302
1182
  c(function () {
1303
- var u = c.fetch('/current_user')
1183
+ var u = c.get('/current_user')
1304
1184
  log('Current user changed!', c.label, JSON.stringify(u))
1305
1185
  if (u.logged_in) {
1306
1186
  log('Yay! We are logged in as', u.user.name)
1307
- forget()
1187
+ c.forget()
1308
1188
  setTimeout(function () {done()}, 200)
1309
1189
  } else
1310
1190
  log("Ok... we aren't logged in yet. We be patient.")
@@ -1312,11 +1192,11 @@ test(function login (done) {
1312
1192
 
1313
1193
  delay(200, () => {
1314
1194
  // c.honk = user0.honk = true
1315
- var u = c.fetch('/current_user')
1195
+ var u = c.get('/current_user')
1316
1196
  u.login_as = {name: 'mike', pass: 'yeah'}
1317
1197
  log('Logging in')
1318
1198
  //s.honk = true
1319
- c.save(u)
1199
+ c.set(u)
1320
1200
  log('Let\'s see if that login worked!!')
1321
1201
  })
1322
1202
  })
@@ -1325,10 +1205,10 @@ test(function wrong_password (done) {
1325
1205
  var {s, c} = setup_servers()
1326
1206
  // s.honk = true; c.honk = true
1327
1207
 
1328
- var u = c.fetch('/current_user')
1208
+ var u = c.get('/current_user')
1329
1209
  //assert(u.logged_in && u.user.name == 'mike')
1330
1210
  u.login_as = {name: 'j', pass: 'nah'}
1331
- c.save(u)
1211
+ c.set(u)
1332
1212
  delay(500, () => {
1333
1213
  assert(!u.login_as, 'Aborted login needs to abort')
1334
1214
  log('Good, the login failed.')
@@ -1344,16 +1224,16 @@ test(function create_account (done) {
1344
1224
 
1345
1225
  delay(500, () => {
1346
1226
  log('Logging in')
1347
- cu = c.fetch('/current_user')
1227
+ cu = c.get('/current_user')
1348
1228
  cu.login_as = {name: 'mike', pass: 'yeah'}
1349
- c.save(cu)
1229
+ c.set(cu)
1350
1230
  })
1351
1231
 
1352
1232
  // Log out
1353
1233
  delay(500, () => {
1354
- assert(c.fetch('/current_user').logged_in)
1234
+ assert(c.get('/current_user').logged_in)
1355
1235
  log('Logging out')
1356
- cu.logout = true; c.save(cu)
1236
+ cu.logout = true; c.set(cu)
1357
1237
  })
1358
1238
 
1359
1239
  // Create bob and log in as bob
@@ -1361,12 +1241,12 @@ test(function create_account (done) {
1361
1241
  log('Creating bob')
1362
1242
  assert(!cu.logged_in, '3 logged in')
1363
1243
  cu.create_account = {name: 'bob', email: 'b@o.b', pass: 'boob'}
1364
- c.save(cu)
1244
+ c.set(cu)
1365
1245
 
1366
1246
  log('Logging in as bob')
1367
1247
  delete cu.create_account
1368
1248
  cu.login_as = {name: 'bob', pass: 'boob'}
1369
- c.save(cu)
1249
+ c.set(cu)
1370
1250
  })
1371
1251
 
1372
1252
  // Log out
@@ -1379,7 +1259,7 @@ test(function create_account (done) {
1379
1259
  'Bad user', cu)
1380
1260
 
1381
1261
  log('Now let\'s log out!')
1382
- cu.logout = true; c.save(cu)
1262
+ cu.logout = true; c.set(cu)
1383
1263
  })
1384
1264
 
1385
1265
  // Log back in as boob
@@ -1387,7 +1267,7 @@ test(function create_account (done) {
1387
1267
  log('Logging back in as boob')
1388
1268
  assert(!cu.logged_in, 'Still logged in, as ' + cu.key)
1389
1269
  cu.login_as = {name: 'bob', pass:'boob'}
1390
- c.save(cu)
1270
+ c.set(cu)
1391
1271
  })
1392
1272
 
1393
1273
  delay(600, () => {
@@ -1408,16 +1288,16 @@ function connections_helper (done, port, options) {
1408
1288
  // Connect two clients
1409
1289
  var c1 = require('../statebus')()
1410
1290
  c1.label = 'c1'
1411
- c1.ws_client('/*', 'statei://localhost:' + port)
1291
+ c1.ws_mount('/*', 'statei://localhost:' + port)
1412
1292
 
1413
1293
  var c2 = require('../statebus')()
1414
1294
  c2.label = 'c2'
1415
- c2.ws_client('/*', 'statei://localhost:' + port)
1295
+ c2.ws_mount('/*', 'statei://localhost:' + port)
1416
1296
 
1417
1297
  // Load the basic connections
1418
- c1.c = c1.fetch('/connection')
1419
- c2.c = c2.fetch('/connection')
1420
- c1.all = c1.fetch('/connections')
1298
+ c1.c = c1.get('/connection')
1299
+ c2.c = c2.get('/connection')
1300
+ c1.all = c1.get('/connections')
1421
1301
 
1422
1302
  delay(50, _=> {
1423
1303
  // Test
@@ -1428,10 +1308,10 @@ function connections_helper (done, port, options) {
1428
1308
  assert(c2.c.id)
1429
1309
 
1430
1310
  // Load the connections inside
1431
- c1.c1 = c1.fetch('/connection/' + c1.c.id)
1432
- c1.c2 = c1.fetch('/connection/' + c2.c.id)
1433
- c2.c1 = c2.fetch('/connection/' + c1.c.id)
1434
- c2.c2 = c2.fetch('/connection/' + c2.c.id)
1311
+ c1.c1 = c1.get('/connection/' + c1.c.id)
1312
+ c1.c2 = c1.get('/connection/' + c2.c.id)
1313
+ c2.c1 = c2.get('/connection/' + c1.c.id)
1314
+ c2.c2 = c2.get('/connection/' + c2.c.id)
1435
1315
  })
1436
1316
 
1437
1317
  delay(50, _=> {
@@ -1445,8 +1325,8 @@ function connections_helper (done, port, options) {
1445
1325
  assert(c2.c2.id === c2.c.id)
1446
1326
 
1447
1327
  // Modify a connection
1448
- c1.c.foo = 'bar'; c1.save(c1.c)
1449
- c2.c2.fuzz = 'buzz'; c2.save(c2.c2)
1328
+ c1.c.foo = 'bar'; c1.set(c1.c)
1329
+ c2.c2.fuzz = 'buzz'; c2.set(c2.c2)
1450
1330
  })
1451
1331
 
1452
1332
  delay(50, _=> {
@@ -1460,8 +1340,8 @@ function connections_helper (done, port, options) {
1460
1340
  assert(c1.c2.fuzz === 'buzz')
1461
1341
 
1462
1342
  // Modify someone else's connection
1463
- c1.c2.fuzz = 'fart'; c1.save(c1.c2)
1464
- c2.c1.free = 'willy'; c2.save(c2.c1)
1343
+ c1.c2.fuzz = 'fart'; c1.set(c1.c2)
1344
+ c2.c1.free = 'willy'; c2.set(c2.c1)
1465
1345
  })
1466
1346
 
1467
1347
  delay(50, _=> {
@@ -1493,9 +1373,9 @@ test(function connections_2 (done) {
1493
1373
  })
1494
1374
 
1495
1375
  test(function flashbacks (done) {
1496
- // We have an echo canceler. If you save state, it shouldn't send the
1376
+ // We have an echo canceler. If you set state, it shouldn't send the
1497
1377
  // same state back to you, but it should send it to everyone else. But if
1498
- // the state is changed in a to_save handler, it *should* send you
1378
+ // the state is changed in a to_set handler, it *should* send you
1499
1379
  // changes.
1500
1380
 
1501
1381
  var port = 3873
@@ -1504,7 +1384,7 @@ test(function flashbacks (done) {
1504
1384
  var s = require('../statebus').serve({port: port, file_store: false})
1505
1385
  s.label = 's'
1506
1386
 
1507
- s('x').to_save = (o, t) => {
1387
+ s('x').to_set = (o, t) => {
1508
1388
  log('Saving x with', o)
1509
1389
  o.x++ // Change the value of o.x a little
1510
1390
  t.done(o)
@@ -1513,19 +1393,19 @@ test(function flashbacks (done) {
1513
1393
  // Connect two clients
1514
1394
  var c1 = require('../statebus')()
1515
1395
  c1.label = 'c1'
1516
- c1.ws_client('*', 'statei://localhost:' + port)
1396
+ c1.ws_mount('*', 'statei://localhost:' + port)
1517
1397
 
1518
1398
  var c2 = require('../statebus')()
1519
1399
  c2.label = 'c2'
1520
- c2.ws_client('*', 'statei://localhost:' + port)
1400
+ c2.ws_mount('*', 'statei://localhost:' + port)
1521
1401
 
1522
- c1.x = c1.fetch('x')
1523
- c2.x = c2.fetch('x')
1402
+ c1.x = c1.get('x')
1403
+ c2.x = c2.get('x')
1524
1404
 
1525
1405
  // Change stuff
1526
1406
  delay(50, _=> {
1527
1407
  c1.x.x = 1
1528
- c1.save(c1.x)
1408
+ c1.set(c1.x)
1529
1409
  })
1530
1410
 
1531
1411
  // Test stuff
@@ -1543,25 +1423,25 @@ test(function common_time (done) {
1543
1423
  b.honk = 3
1544
1424
 
1545
1425
  // Define a `front' that proxies for `back'
1546
- b('front').to_fetch = () => {
1547
- var copy = b.clone(b.fetch('back'))
1426
+ b('front').to_get = () => {
1427
+ var copy = b.clone(b.get('back'))
1548
1428
  copy.key = 'front'
1549
1429
  return copy
1550
1430
  }
1551
- b('front').to_save = (o, t) => {
1431
+ b('front').to_set = (o, t) => {
1552
1432
  var copy = b.clone(o)
1553
1433
  copy.key = 'back'
1554
1434
 
1555
1435
  if (copy.special)
1556
1436
  copy.alert = true
1557
1437
 
1558
- b.save.sync(copy)
1438
+ b.set.sync(copy)
1559
1439
  }
1560
1440
 
1561
1441
  // Register a handler to see how things change
1562
1442
  var i = 0
1563
1443
  b(() => {
1564
- var front = b.fetch('front')
1444
+ var front = b.get('front')
1565
1445
  log('Looks like front is currently', front, b.versions.front, '!')
1566
1446
 
1567
1447
  // Test it!
@@ -1575,11 +1455,11 @@ test(function common_time (done) {
1575
1455
  })
1576
1456
 
1577
1457
  // Now make changes through front
1578
- delay(50, _=> b.save({key: 'front', val: 'bar1'}))
1579
- delay(50, _=> b.save({key: 'front', val: 'bar2'}, {version: 'x2'}))
1580
- delay(50, _=> b.save({key: 'front', val: 'bar2'}, {version: 'x2.2'}))
1581
- delay(50, _=> b.save({key: 'front', val: 'bar3'}, {version: 'x3'}))
1582
- delay(50, _=> b.save({key: 'front'}, {version: '_'}))
1458
+ delay(50, _=> b.set({key: 'front', val: 'bar1'}))
1459
+ delay(50, _=> b.set({key: 'front', val: 'bar2'}, {version: 'x2'}))
1460
+ delay(50, _=> b.set({key: 'front', val: 'bar2'}, {version: 'x2.2'}))
1461
+ delay(50, _=> b.set({key: 'front', val: 'bar3'}, {version: 'x3'}))
1462
+ delay(50, _=> b.set({key: 'front'}, {version: '_'}))
1583
1463
 
1584
1464
  delay(0, _=> log('Now trying with a client.'))
1585
1465
 
@@ -1596,21 +1476,21 @@ test(function common_time (done) {
1596
1476
  }
1597
1477
 
1598
1478
  // Make a couple changes. These should go through.
1599
- delay(50, _=> b.fetch('front', client))
1600
- delay(50, _=> b.save({key: 'front', val: 'foo1'}, {version: 'y1'}))
1479
+ delay(50, _=> b.get('front', client))
1480
+ delay(50, _=> b.set({key: 'front', val: 'foo1'}, {version: 'y1'}))
1601
1481
 
1602
1482
  // Now make some changes that the client has already seen
1603
1483
  delay(50, _=> {
1604
1484
  client.has_seen(b, 'front', 'y2')
1605
- b.save({key: 'front', val: 'foo2'}, {version: 'y2'})
1485
+ b.set({key: 'front', val: 'foo2'}, {version: 'y2'})
1606
1486
  })
1607
1487
  delay(50, _=> {
1608
1488
  client.has_seen(b, 'front', 'y3')
1609
- b.save({key: 'front', val: 'foo3', special: true}, {version: 'y3'})
1489
+ b.set({key: 'front', val: 'foo3', special: true}, {version: 'y3'})
1610
1490
  })
1611
1491
 
1612
1492
  // And one it hasn't seen again
1613
- delay(50, _=> b.save({key: 'front', val: 'foo4'}, {version: 'y4'}))
1493
+ delay(50, _=> b.set({key: 'front', val: 'foo4'}, {version: 'y4'}))
1614
1494
 
1615
1495
  // And we're done!
1616
1496
  delay(50, done)
@@ -1630,7 +1510,7 @@ if (false) {
1630
1510
  function () {
1631
1511
  log('Logging in as mike')
1632
1512
  //s.honk=true
1633
- u.login_as = {name: 'mike', pass: 'yeah'}; c.save(u)
1513
+ u.login_as = {name: 'mike', pass: 'yeah'}; c.set(u)
1634
1514
  }],
1635
1515
 
1636
1516
  // Phase 1
@@ -1654,7 +1534,7 @@ if (false) {
1654
1534
  tmp1 = true
1655
1535
  log('Firing the actual j login')
1656
1536
  //s.userbus.honk = true
1657
- u.login_as = {name: 'j', pass: 'yeah'}; c.save(u)
1537
+ u.login_as = {name: 'j', pass: 'yeah'}; c.set(u)
1658
1538
  log('We just logged in as j. now user is:', u.user.name)
1659
1539
  }, 10)
1660
1540
  }],
@@ -1677,23 +1557,23 @@ if (false) {
1677
1557
  function () { log("That's all, Doc."); setTimeout(function () {done()}) }]
1678
1558
  ]}
1679
1559
 
1680
- c('/current_user').on_save = function (o) {
1560
+ c('/current_user').on_set = function (o) {
1681
1561
  //if (o.user && o.user.name === 'j') {
1682
1562
  // log(s.userbus.deps('/current_user'))
1683
1563
  // log(s.userbus.deps('/user/2'))
1684
1564
  //}
1685
1565
  }
1686
- c('/user/*').on_save = function (o) {
1566
+ c('/user/*').on_set = function (o) {
1687
1567
  //log('-> Got new', o.key, o.email ? 'with email' : '')
1688
1568
  }
1689
- c('/current_user').on_save = function (o) {
1569
+ c('/current_user').on_set = function (o) {
1690
1570
  //log('-> Got new /current_user')
1691
1571
  }
1692
1572
  c(function loop () {
1693
- u = c.fetch('/current_user')
1694
- user1 = c.fetch('/user/1')
1695
- user2 = c.fetch('/user/2')
1696
- user3 = c.fetch('/user/3')
1573
+ u = c.get('/current_user')
1574
+ user1 = c.get('/user/1')
1575
+ user2 = c.get('/user/2')
1576
+ user3 = c.get('/user/3')
1697
1577
  var st = states()
1698
1578
 
1699
1579
  if (phase===1)
@@ -1723,18 +1603,18 @@ if (false) {
1723
1603
 
1724
1604
  var c = require('../statebus')()
1725
1605
  c.label = 'c'
1726
- c.ws_client('/*', 'statei://localhost:3949')
1606
+ c.ws_mount('/*', 'statei://localhost:3949')
1727
1607
 
1728
1608
  // Make stuff as user A
1729
- var cu = c.fetch('/current_user')
1730
- c.save({key: '/current_user', create_account: {name: 'a', pass: 'a'}})
1731
- c.save({key: '/current_user', login_as: {name: 'a', pass: 'a'}})
1732
- var a_closet = c.fetch('/user/a/foo')
1733
- var a_private = c.fetch('/user/a/private/foo')
1609
+ var cu = c.get('/current_user')
1610
+ c.set({key: '/current_user', create_account: {name: 'a', pass: 'a'}})
1611
+ c.set({key: '/current_user', login_as: {name: 'a', pass: 'a'}})
1612
+ var a_closet = c.get('/user/a/foo')
1613
+ var a_private = c.get('/user/a/private/foo')
1734
1614
 
1735
1615
  delay(400, () => {
1736
- c.save({key: '/user/a/foo', _: 3})
1737
- c.save({key: '/user/a/private/foo', _: 4})
1616
+ c.set({key: '/user/a/foo', _: 3})
1617
+ c.set({key: '/user/a/private/foo', _: 4})
1738
1618
  })
1739
1619
 
1740
1620
  // User A can see it
@@ -1746,8 +1626,8 @@ if (false) {
1746
1626
  assert(a_private._ === 4, 'private not right')
1747
1627
 
1748
1628
  // Set up User B
1749
- c.save({key: '/current_user', create_account: {name: 'b', pass: 'b'}})
1750
- c.save({key: '/current_user', login_as: {name: 'b', pass: 'b'}})
1629
+ c.set({key: '/current_user', create_account: {name: 'b', pass: 'b'}})
1630
+ c.set({key: '/current_user', login_as: {name: 'b', pass: 'b'}})
1751
1631
  })
1752
1632
 
1753
1633
  // User B can't see private stuff
@@ -1758,7 +1638,7 @@ if (false) {
1758
1638
  assert(a_private._ !== 4, 'damn can still see private')
1759
1639
 
1760
1640
  // User B tries editing the first closet
1761
- a_closet._ = 5; c.save(a_closet)
1641
+ a_closet._ = 5; c.set(a_closet)
1762
1642
  })
1763
1643
 
1764
1644
  // User B could not edit that
@@ -1774,21 +1654,21 @@ if (false) {
1774
1654
  // Not fully implemented yet
1775
1655
 
1776
1656
  /*
1777
- Let's save within an on-save handler. Which will trigger
1778
- first... the dirty(), or the new save()? Hm, do we really
1657
+ Let's set within an on-set handler. Which will trigger
1658
+ first... the dirty(), or the new set()? Hm, do we really
1779
1659
  care?
1780
1660
  */
1781
1661
 
1782
1662
  var user = 3
1783
- bus('user').to_fetch =
1663
+ bus('user').to_get =
1784
1664
  function (k) {
1785
1665
  return {user: user}
1786
1666
  }
1787
1667
 
1788
- bus('user').to_save =
1668
+ bus('user').to_set =
1789
1669
  function (o) {
1790
1670
  if (o.funny)
1791
- bus.save({key: 'user', user: 'funny'})
1671
+ bus.set({key: 'user', user: 'funny'})
1792
1672
 
1793
1673
  user = o.user
1794
1674
  bus.dirty('user')