|
|
@ -1,7 +1,7 @@ |
|
|
|
import type { Diff as Patches, Scope } from "../types.ts"; |
|
|
|
import type { Diff as Patches, Scope } from "../types.ts"; |
|
|
|
import { applyDiff } from "./applyDiff.ts"; |
|
|
|
import { applyDiff } from "./applyDiff.ts"; |
|
|
|
|
|
|
|
|
|
|
|
import { ng } from "./initNg.ts"; |
|
|
|
import { ngSession } from "./initNg.ts"; |
|
|
|
|
|
|
|
|
|
|
|
import { |
|
|
|
import { |
|
|
|
deepSignal, |
|
|
|
deepSignal, |
|
|
@ -11,7 +11,6 @@ import { |
|
|
|
import type { |
|
|
|
import type { |
|
|
|
DeepPatch, |
|
|
|
DeepPatch, |
|
|
|
DeepSignalObject, |
|
|
|
DeepSignalObject, |
|
|
|
WatchPatchCallback, |
|
|
|
|
|
|
|
WatchPatchEvent, |
|
|
|
WatchPatchEvent, |
|
|
|
} from "@ng-org/alien-deepsignals"; |
|
|
|
} from "@ng-org/alien-deepsignals"; |
|
|
|
import type { ShapeType, BaseType } from "@ng-org/shex-orm"; |
|
|
|
import type { ShapeType, BaseType } from "@ng-org/shex-orm"; |
|
|
@ -27,7 +26,6 @@ export class OrmConnection<T extends BaseType> { |
|
|
|
/*** Identifier as a combination of shape type and scope. Prevents duplications. */ |
|
|
|
/*** Identifier as a combination of shape type and scope. Prevents duplications. */ |
|
|
|
private identifier: string; |
|
|
|
private identifier: string; |
|
|
|
ready: boolean; |
|
|
|
ready: boolean; |
|
|
|
sessionId: number; |
|
|
|
|
|
|
|
suspendDeepWatcher: boolean; |
|
|
|
suspendDeepWatcher: boolean; |
|
|
|
readyPromise: Promise<void>; |
|
|
|
readyPromise: Promise<void>; |
|
|
|
// Promise that resolves once initial data has been applied.
|
|
|
|
// Promise that resolves once initial data has been applied.
|
|
|
@ -56,9 +54,6 @@ export class OrmConnection<T extends BaseType> { |
|
|
|
idGenerator: this.generateSubjectIri, |
|
|
|
idGenerator: this.generateSubjectIri, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// TODO:
|
|
|
|
|
|
|
|
this.sessionId = 1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Schedule cleanup of the connection when the signal object is GC'd.
|
|
|
|
// Schedule cleanup of the connection when the signal object is GC'd.
|
|
|
|
OrmConnection.cleanupSignalRegistry?.register( |
|
|
|
OrmConnection.cleanupSignalRegistry?.register( |
|
|
|
this.signalObject, |
|
|
|
this.signalObject, |
|
|
@ -74,14 +69,11 @@ export class OrmConnection<T extends BaseType> { |
|
|
|
this.resolveReady = resolve; |
|
|
|
this.resolveReady = resolve; |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
new Promise(async () => { |
|
|
|
ngSession.then(({ ng, session }) => { |
|
|
|
// Establish connection to wasm land.
|
|
|
|
|
|
|
|
await new Promise((resolve) => setTimeout(resolve, 100)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ng.orm_start( |
|
|
|
ng.orm_start( |
|
|
|
scope, |
|
|
|
scope, |
|
|
|
shapeType, |
|
|
|
shapeType, |
|
|
|
this.sessionId, |
|
|
|
session.session_id, |
|
|
|
this.onBackendMessage |
|
|
|
this.onBackendMessage |
|
|
|
); |
|
|
|
); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -98,8 +90,6 @@ export class OrmConnection<T extends BaseType> { |
|
|
|
shapeType: ShapeType<T>, |
|
|
|
shapeType: ShapeType<T>, |
|
|
|
scope: Scope |
|
|
|
scope: Scope |
|
|
|
): OrmConnection<T> { |
|
|
|
): OrmConnection<T> { |
|
|
|
// if (!ng) throw new Error("initNg was not called yet.");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const scopeKey = canonicalScope(scope); |
|
|
|
const scopeKey = canonicalScope(scope); |
|
|
|
|
|
|
|
|
|
|
|
// Unique identifier for a given shape type and scope.
|
|
|
|
// Unique identifier for a given shape type and scope.
|
|
|
@ -108,13 +98,15 @@ export class OrmConnection<T extends BaseType> { |
|
|
|
// If we already have an object for this shape+scope,
|
|
|
|
// If we already have an object for this shape+scope,
|
|
|
|
// return it and just increase the reference count.
|
|
|
|
// return it and just increase the reference count.
|
|
|
|
// Otherwise, create new one.
|
|
|
|
// Otherwise, create new one.
|
|
|
|
const connection = |
|
|
|
const existingConnection = OrmConnection.idToEntry.get(identifier); |
|
|
|
OrmConnection.idToEntry.get(identifier) ?? |
|
|
|
if (existingConnection) { |
|
|
|
new OrmConnection(shapeType, scope); |
|
|
|
existingConnection.refCount += 1; |
|
|
|
|
|
|
|
return existingConnection; |
|
|
|
connection.refCount += 1; |
|
|
|
} else { |
|
|
|
|
|
|
|
const newConnection = new OrmConnection(shapeType, scope); |
|
|
|
return connection; |
|
|
|
OrmConnection.idToEntry.set(identifier, newConnection); |
|
|
|
|
|
|
|
return newConnection; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public release() { |
|
|
|
public release() { |
|
|
@ -131,12 +123,14 @@ export class OrmConnection<T extends BaseType> { |
|
|
|
|
|
|
|
|
|
|
|
const ormPatches = deepPatchesToDiff(patches); |
|
|
|
const ormPatches = deepPatchesToDiff(patches); |
|
|
|
|
|
|
|
|
|
|
|
ng.orm_update( |
|
|
|
ngSession.then(({ ng, session }) => { |
|
|
|
this.scope, |
|
|
|
ng.orm_update( |
|
|
|
this.shapeType.shape, |
|
|
|
this.scope, |
|
|
|
ormPatches, |
|
|
|
this.shapeType.shape, |
|
|
|
this.sessionId |
|
|
|
ormPatches, |
|
|
|
); |
|
|
|
session.session_id |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private onBackendMessage(...message: any) { |
|
|
|
private onBackendMessage(...message: any) { |
|
|
|