This repository has been archived by the owner on Nov 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Note that the state is not propagated to the other clients, after the state had been succesfully updated. In effect, the only purpose of the state is to give a new user its initial state. Its the duty of every client to send their changes directly to the other clients (that's the idea of websockets)
- Loading branch information
Showing
9 changed files
with
310 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { expect } from 'chai' | ||
import { StateEvent } from './state.event' | ||
|
||
describe('Events', () => { | ||
describe('StateEvent', () => { | ||
it("should have 'state' event as name", () => { | ||
expect(StateEvent.eventName).to.equal('state') | ||
}) | ||
it('should initialize an object', () => { | ||
// arrange | ||
const state: object = { | ||
points: [{ x: 1, y: 2 }], | ||
imageSrc: 'lake.png', | ||
} | ||
|
||
// act | ||
const event = new StateEvent(state) | ||
|
||
// assert | ||
expect(event.state).to.deep.equal(state) | ||
}) | ||
}) | ||
}) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { EventToClient } from './event.to.client' | ||
|
||
export class StateEvent { | ||
static eventName: string = EventToClient.State | ||
constructor(public readonly state: object) {} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { expect } from 'chai' | ||
import { UpdateStateEvent } from './update.state.event' | ||
import Automerge from 'automerge' | ||
|
||
describe('Events', () => { | ||
describe('UpdateStateEvent', () => { | ||
it("should have 'update-state' event as name", () => { | ||
expect(UpdateStateEvent.eventName).to.equal('update-state') | ||
}) | ||
it('should initialize an array of Change objects', () => { | ||
// arrange | ||
const changes: Automerge.Change[] = [ | ||
{ | ||
ops: [ | ||
{ | ||
action: 'makeList', | ||
obj: 'be89e397-324c-4bec-932a-ae087a3177de', | ||
}, | ||
{ | ||
action: 'ins', | ||
obj: 'be89e397-324c-4bec-932a-ae087a3177de', | ||
key: '_head', | ||
elem: 1, | ||
}, | ||
{ | ||
action: 'makeMap', | ||
obj: '8b94a2c5-98c3-4ed9-8a18-ccae369cf168', | ||
}, | ||
{ | ||
action: 'set', | ||
obj: '8b94a2c5-98c3-4ed9-8a18-ccae369cf168', | ||
key: 'x', | ||
value: 1, | ||
}, | ||
{ | ||
action: 'set', | ||
obj: '8b94a2c5-98c3-4ed9-8a18-ccae369cf168', | ||
key: 'y', | ||
value: 2, | ||
}, | ||
{ | ||
action: 'link', | ||
obj: 'be89e397-324c-4bec-932a-ae087a3177de', | ||
key: 'b6336846-12b7-4d8c-a4ab-949a3afd1903:1', | ||
value: '8b94a2c5-98c3-4ed9-8a18-ccae369cf168', | ||
}, | ||
{ | ||
action: 'link', | ||
obj: '00000000-0000-0000-0000-000000000000', | ||
key: 'points', | ||
value: 'be89e397-324c-4bec-932a-ae087a3177de', | ||
}, | ||
{ | ||
action: 'set', | ||
obj: '00000000-0000-0000-0000-000000000000', | ||
key: 'imageSrc', | ||
value: 'lake.png', | ||
}, | ||
], | ||
actor: 'b6336846-12b7-4d8c-a4ab-949a3afd1903', | ||
seq: 1, | ||
deps: {}, | ||
}, | ||
] | ||
|
||
// act | ||
const event = new UpdateStateEvent(changes) | ||
|
||
// assert | ||
expect(event.data).to.deep.equal(changes) | ||
}) | ||
}) | ||
}) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { EventToServer } from './event.to.server' | ||
import Automerge from 'automerge' | ||
|
||
export class UpdateStateEvent { | ||
static eventName: string = EventToServer.UpdateState | ||
constructor(public readonly data: Automerge.Change[]) {} | ||
} |
This file contains 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
This file contains 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
This file contains 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