Skip to content

Commit 188edd6

Browse files
committed
add new failing test case: 'replacing collection of items while keeping a reference to an item'
1 parent 1c1c2c6 commit 188edd6

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

test/InstanceSharing.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,4 +460,48 @@ describe("Instance sharing", () => {
460460

461461
});
462462

463+
xit("replacing collection of items while keeping a reference to an item", () => {
464+
class Song extends Schema {
465+
@type("string") url: string;
466+
}
467+
468+
class Player extends Schema {
469+
@type([Song]) queue = new ArraySchema<Song>();
470+
}
471+
472+
class State extends Schema {
473+
@type(Song) playing: Song = new Song();
474+
@type([Song]) queue = new ArraySchema<Song>();
475+
@type({ map: Player }) buckets = new MapSchema<Player>();
476+
}
477+
478+
const sessionId = "";
479+
480+
const state = new State();
481+
const decodedState = new State();
482+
483+
console.log(">> encode()")
484+
decodedState.decode(state.encode());
485+
486+
state.buckets.set(sessionId, new Player());
487+
488+
console.log(">> encode()")
489+
decodedState.decode(state.encode());
490+
console.log(Schema.debugRefIds(state));
491+
492+
const newSong = new Song().assign({ url: "song2" });
493+
state.buckets.get(sessionId).queue.push(newSong);
494+
495+
state.queue = new ArraySchema<Song>();
496+
state.queue.push(newSong);
497+
498+
state.playing = state.buckets.get(sessionId).queue.shift();
499+
state.queue = new ArraySchema<Song>();
500+
501+
console.log(">> encode()")
502+
console.log(Schema.debugRefIds(state));
503+
decodedState.decode(state.encode());
504+
assert.deepStrictEqual(state.toJSON(), decodedState.toJSON());
505+
});
506+
463507
});

0 commit comments

Comments
 (0)