Skip to content

Commit

Permalink
FIX build
Browse files Browse the repository at this point in the history
  • Loading branch information
pubkey committed Feb 3, 2025
1 parent e393890 commit e729d46
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 40 deletions.
2 changes: 1 addition & 1 deletion docs-src/docs/replication.md
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ const replicationState = replicateRxCollection({

`(experimental)`

Set this to true to ensure the replication also runs if the tab is currently `visbile`. This fixes problem in browsers where the replicating leader-elected tab becomes stale or hibernated by the browser to save battery life. If the tab is loosing visibility, the replication will be paused automatically and then restarted if either the tab becomes leader or the tab becomes visible again.
Set this to true to ensure the replication also runs if the tab is currently `visbile`. This fixes problem in browsers where the replicating leader-elected tab becomes stale or hibernated by the browser to save battery life. If the tab is losing visibility, the replication will be paused automatically and then restarted if either the tab becomes leader or the tab becomes visible again.

```ts
const replicationState = replicateRxCollection({
Expand Down
11 changes: 0 additions & 11 deletions src/plugins/replication/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,30 +155,24 @@ export class RxReplicationState<RxDocType, CheckpointType> {
public remoteEvents$: Subject<RxReplicationPullStreamItem<RxDocType, CheckpointType>> = new Subject();

public async start(): Promise<void> {
console.log('replicationState.start() 0');
if (this.isStopped()) {
return;
}

console.log('replicationState.start() 1');
if (this.internalReplicationState) {
this.internalReplicationState.events.paused.next(false);
}
console.log('replicationState.start() 2');

/**
* If started after a pause,
* just re-sync once and continue.
*/
if (this.wasStarted) {
console.log('replicationState.start() 3');
this.reSync();
return;
}
console.log('replicationState.start() 4');
this.wasStarted = true;


preventHibernateBrowserTab(this);


Expand Down Expand Up @@ -225,8 +219,6 @@ export class RxReplicationState<RxDocType, CheckpointType> {
masterChangeStream$: this.remoteEvents$.asObservable().pipe(
filter(_v => !!this.pull),
mergeMap(async (ev) => {
console.log('masterChangeStream$ emit:');
console.dir(ev);
if (ev === 'RESYNC') {
return ev;
}
Expand Down Expand Up @@ -290,8 +282,6 @@ export class RxReplicationState<RxDocType, CheckpointType> {
masterWrite: async (
rows: RxReplicationWriteToMasterRow<RxDocType>[]
) => {
console.log('masterWrite()');

if (!this.push) {
return [];
}
Expand Down Expand Up @@ -491,7 +481,6 @@ export class RxReplicationState<RxDocType, CheckpointType> {
}

reSync() {
console.log('replicationState.reSync()');
this.remoteEvents$.next('RESYNC');
}
emitEvent(ev: RxReplicationPullStreamItem<RxDocType, CheckpointType>) {
Expand Down
4 changes: 0 additions & 4 deletions src/replication-protocol/checkpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ export async function setCheckpoint<RxDocType, CheckpointType>(
direction: RxStorageReplicationDirection,
checkpoint: CheckpointType
) {
console.log('..................... setCheckpoint(' + direction + '):');
console.dir(checkpoint);
state.checkpointQueue = state.checkpointQueue.then(async () => {
let previousCheckpointDoc = state.lastCheckpointDoc[direction];
if (
Expand Down Expand Up @@ -125,8 +123,6 @@ export async function setCheckpoint<RxDocType, CheckpointType>(
)[0];
if (successDoc) {
state.lastCheckpointDoc[direction] = successDoc;
console.log('..................... setCheckpoint(' + direction + ') DONE:');
console.dir(successDoc);
return;
} else {
const error = result.error[0];
Expand Down
5 changes: 0 additions & 5 deletions src/replication-protocol/downstream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ export async function startReplicationDownstream<RxDocType, CheckpointType = any


function addNewTask(task: Task): void {
console.log('downstream addNewTask():');
console.dir(task);
state.stats.down.addNewTask = state.stats.down.addNewTask + 1;
const taskWithTime = {
time: timer++,
Expand Down Expand Up @@ -146,16 +144,13 @@ export async function startReplicationDownstream<RxDocType, CheckpointType = any
.masterChangeStream$
.pipe(
mergeMap(async (ev) => {
console.log('downstream: masterChangeStream$ emitted 1');
console.dir(ev);
/**
* While a push is running, we have to delay all incoming
* events from the server to not mix up the replication state.
*/
await firstValueFrom(
state.events.active.up.pipe(filter(s => !s))
);
console.log('downstream: masterChangeStream$ emitted 2');
return ev;
})
)
Expand Down
2 changes: 1 addition & 1 deletion src/types/plugins/replication.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export type ReplicationOptions<RxDocType, CheckpointType> = {
* Like 'my-rest-replication-to-https://example.com/api/sync'
*/
replicationIdentifier: string;
collection: RxCollection<RxDocType>;
collection: RxCollection<RxDocType, any, any, any>;
/**
* Define a custom property that is used
* to flag a document as being deleted.
Expand Down
18 changes: 0 additions & 18 deletions test/unit/replication.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1051,51 +1051,33 @@ describe('replication.test.ts', () => {
await replicationState.awaitInitialReplication();
await replicationState.awaitInSync();

console.log('------------------- before pause 0');
await replicationState.pause();
console.log('------------------- after pause 0');

const insertAfterPauseId = 'insert after pause';
await localCollection.insert(schemaObjects.humanWithTimestampData({ id: insertAfterPauseId + '-local' }));
console.log('------------------- after insert ' + replicationState.isPaused());

// should not have been synced
await wait(isFastMode() ? 10 : 50);
let remoteDocs = await remoteCollection.find().exec();
assert.deepEqual(remoteDocs.length, startDocsAmount * 2);

// restart after local write
console.log('------------ before restart');
await replicationState.start();
console.log('------------ after restart 0');
await replicationState.awaitInSync();
console.log('------------ after restart 1');
await wait(200);
console.log('------------ after restart 2');
remoteDocs = await remoteCollection.find().exec();
assert.deepEqual(remoteDocs.length, (startDocsAmount * 2) + 1);

// restart after remote write
console.log('######### RESTART AFTER REMOTE WRITE!');
await replicationState.pause();
console.log('######### RESTART AFTER REMOTE WRITE after pause');
await remoteCollection.insert(schemaObjects.humanWithTimestampData({ id: insertAfterPauseId + '-remote' }));
console.log('######### RESTART AFTER REMOTE WRITE after insert');
await wait(isFastMode() ? 10 : 50);
console.log('######### RESTART AFTER REMOTE WRITE after wait');
let localDocs = await localCollection.find().exec();
assert.deepEqual(localDocs.length, (startDocsAmount * 2) + 1);
await replicationState.start();
console.log('######### RESTART AFTER REMOTE WRITE after restart');
await replicationState.awaitInSync();
localDocs = await localCollection.find().exec();
assert.deepEqual(localDocs.length, (startDocsAmount * 2) + 2);



console.log('WORKS !!');
process.exit();

localCollection.database.close();
remoteCollection.database.close();
});
Expand Down

0 comments on commit e729d46

Please sign in to comment.