git ssb

0+

wanderer🌟 / js-primea-message



Commit d2d025b4ddd924dc333fd8fbc3915624a26c9f09

update to rename for caps

Signed-off-by: wanderer <mjbecze@gmail.com>
wanderer committed on 11/14/2017, 12:56:46 AM
Parent: bfd6fba3723499dceee6f8c9fd1c2af03931c986

Files changed

index.jschanged
tests/index.jschanged
index.jsView
@@ -11,9 +11,9 @@
1111 constructor (opts = {}) {
1212 const defaults = {
1313 ticks: 0,
1414 data: new ArrayBuffer([]),
15- ports: []
15 + caps: []
1616 }
1717
1818 this._opts = Object.assign(defaults, opts)
1919
@@ -38,10 +38,10 @@
3838 /**
3939 * Returns an array of ports that a message is carrying
4040 * @returns {[]}
4141 */
42- get ports () {
43- return this._opts.ports
42 + get caps () {
43 + return this._opts.caps
4444 }
4545
4646 /**
4747 * Returns the messages payload
@@ -54,10 +54,10 @@
5454 /**
5555 * Returns the port from which the message arrived
5656 * @returns {*}
5757 */
58- get fromPort () {
59- return this._fromPort
58 + get from () {
59 + return this._from
6060 }
6161
6262 /**
6363 * returns the number of hops a packet has undergone
tests/index.jsView
@@ -1,24 +1,27 @@
11 const tape = require('tape')
22 const Message = require('../')
33
44 tape('message API tests', async t => {
5- const aPort = {}
6- const json = '{"ticks":77,"data":{"type":"Buffer","data":[116,101,115,116]},"ports":[{}]}'
5 + const capA = {}
6 + const json = '{"ticks":77,"data":{"type":"Buffer","data":[116,101,115,116]},"caps":[{}]}'
77
88 const params = {
99 data: Buffer.from('test'),
10- ports: [aPort],
10 + caps: [capA],
1111 ticks: 77
1212 }
1313
1414 let message = new Message(params)
15- message._fromPort = 'test'
15 + message._from = 'test'
1616
17- t.equals(message.fromPort, 'test', 'to getter should work')
18- t.equals(message.ports[0], aPort, 'to getter should work')
17 + t.equals(message.from, 'test', 'to getter should work')
18 + t.equals(message.caps[0], capA, 'to getter should work')
1919 t.equals(message.data.toString(), 'test', 'to getter should work')
2020 t.equals(message.ticks, 77, 'resources getter should work')
2121 t.equals(message.hops, 0, 'hops should return correctly')
2222 t.equals(JSON.stringify(message), json)
23 +
24 + message = new Message()
25 + t.equals(message.ticks, 0, 'resources getter should work')
2326 t.end()
2427 })

Built with git-ssb-web