*Change setData to a setter
This commit is contained in:
parent
e4e18a8a55
commit
0016903687
|
@ -36,6 +36,14 @@ export default class DHTOnlineBase extends EventEmitter {
|
|||
return this._data;
|
||||
}
|
||||
|
||||
set data(value: {}) {
|
||||
this._data = value;
|
||||
|
||||
this._setPeer(this.id, value);
|
||||
|
||||
this._broadcastData();
|
||||
}
|
||||
|
||||
private _online: string[];
|
||||
|
||||
get online(): string[] {
|
||||
|
@ -50,14 +58,6 @@ export default class DHTOnlineBase extends EventEmitter {
|
|||
return this.graph.node.get(this._maybeHexify(id));
|
||||
}
|
||||
|
||||
public setData(data: any) {
|
||||
this._data = data;
|
||||
|
||||
this._setPeer(this.id, data);
|
||||
|
||||
this._broadcastData();
|
||||
}
|
||||
|
||||
protected onAddPeer(id: Buffer) {
|
||||
const stringId = id.toString("hex");
|
||||
if (this.connectedTo.has(stringId)) {
|
||||
|
|
|
@ -23,7 +23,7 @@ export default class DHTOnline extends DHTOnlineBase {
|
|||
this.flood.send(peer, Buffer.from("hello"), 0)
|
||||
);
|
||||
|
||||
this.setData(data);
|
||||
this.data = data;
|
||||
|
||||
[...this.swarm.peers.values()].forEach(this.handlePeerAdd.bind(this));
|
||||
}
|
||||
|
|
4
test.js
4
test.js
|
@ -22,8 +22,8 @@ test("Basic presence test / data propagation", (t) => {
|
|||
const p1 = new DHTOnline(peer1);
|
||||
const p2 = new DHTOnline(peer2);
|
||||
|
||||
p1.setData({ message: "Hello" });
|
||||
p2.setData({ message: "World!" });
|
||||
p1.data = { message: "Hello" };
|
||||
p2.data = { message: "World!" };
|
||||
|
||||
t.ok(p1.id, "Generated id 1");
|
||||
t.ok(p2.id, "Generated id 2");
|
||||
|
|
Loading…
Reference in New Issue