Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
franzzua committed Dec 26, 2023
1 parent f4b520c commit 43df9c8
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 25 deletions.
8 changes: 7 additions & 1 deletion core/di/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ export class Container {
try {
return this.resolve(existing, overrides);
}catch (e){
throw new Error(`Could not resolve provider ${target}` +'\n' + e.message)
const err = new Error(`Could not resolve provider ${target}`);
err.cause = e;
// @ts-ignore
err.original_error = e;
err.stack = err.stack.split('\n').slice(0,2).join('\n') + '\n' +
e.stack
throw err;
}
}

Expand Down
33 changes: 27 additions & 6 deletions domain/entry/modelProxy.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {Stream} from "../streams/stream";
import {ModelAction, ModelLike, ModelPath} from "../shared/types";
import {ModelAction, ModelKey, ModelLike, ModelPath} from "../shared/types";
import {AsyncQueue, Injectable} from "@cmmn/core";
import {VersionState} from "../streams/versionState";
import {Locator} from "../shared/locator";
import {EntityLocator} from "./entity-locator.service";
import {ModelMap} from "../model-map";

@Injectable(true)
export class ModelProxy<TState, TActions extends ModelAction = {}> implements ModelLike<TState, TActions>{
Expand Down Expand Up @@ -74,11 +75,31 @@ export class ModelProxy<TState, TActions extends ModelAction = {}> implements Mo
}));
}

public GetSubProxy<TState, TActions extends ModelAction, TModelProxy extends ModelProxy<TState, TActions> = ModelProxy<TState, TActions>>(
path: ModelPath, modelProxyConstructor: {
new(...args): TModelProxy
} = ModelProxy as any): TModelProxy {
return this.locator.get<TState, TActions>(path, modelProxyConstructor) as TModelProxy;
public GetSubProxy<
UState, UActions extends ModelAction,
UModelProxy extends ModelProxy<UState, UActions> = ModelProxy<UState, UActions>
>(
path: ModelPath,
modelProxyConstructor: {
new(...args): UModelProxy
} = ModelProxy as any): UModelProxy {
return this.locator.get<UState, UActions>(path, modelProxyConstructor) as UModelProxy;
}

public GetSubProxyMap<
UModelProxy extends ModelProxy<UState, UActions>,
UState,
UActions extends ModelAction,
>(
getKeys: () => ReadonlyArray<ModelKey>,
getPath: (key: ModelKey) => ModelPath,
modelProxyConstructor: {
new(...args): UModelProxy
} = ModelProxy as any
): ModelMap<UModelProxy, UState, UActions> {
return new ModelMap<UModelProxy, UState, UActions>(
this.stream, this.locator, getKeys, modelProxyConstructor, getPath
)
}
public equals(x: any) {
return this === x;
Expand Down
2 changes: 1 addition & 1 deletion domain/entry/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function useStreamDomain(): Container {
}

export function useWorkerDomain(worker: Worker | SharedWorker): Container {
const stream = new WorkerStream(worker instanceof SharedWorker ? worker.port : worker);
const stream = new WorkerStream(worker instanceof SharedWorker ? worker.port : worker) ;
return Container.withProviders({
provide: Locator, useClass: EntityLocator
}, {
Expand Down
12 changes: 9 additions & 3 deletions domain/model-map.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import {ModelProxy, ModelAction, ModelKey, Stream, Locator, ModelPath} from "@cmmn/domain/proxy";
import {ModelProxy} from "./entry/modelProxy";
import {ModelAction, ModelKey, ModelPath} from "./shared/types";
import {Stream} from "./streams/stream";
import {Locator} from "./shared/locator";

export class ModelMap<TModelProxy
extends ModelProxy<TState, TActions>, TState = any, TActions extends ModelAction = {}>
export class ModelMap<
TModelProxy extends ModelProxy<TState, TActions>,
TState,
TActions extends ModelAction
>
implements ReadonlyMap<ModelKey, TModelProxy> {
constructor(private stream: Stream,
private locator: Locator,
Expand Down
4 changes: 2 additions & 2 deletions domain/streams/versionState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ export class VersionState<T> extends Cell<T> {
public waitLoaded = new ResolvablePromise<void>();
private isLoaded: boolean;

constructor(options: ICellOptions<T>) {
constructor(options: ICellOptions<T> = {}) {
super(() => {
if (this.localVersion && this.remoteVersion < this.localVersion)
if (this.localVersion && (this.remoteVersion ?? '') < this.localVersion)
return this.localState;
return this.remoteState;
}, options);
Expand Down
19 changes: 8 additions & 11 deletions domain/streams/workerStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {Action, ModelPath, WorkerMessage, WorkerMessageType} from '../shared/typ
import {VersionState} from './versionState.js';
import {BaseStream} from './base.stream.js';
import {Stream} from './stream.js';
import {Cell} from "@cmmn/cell";

/**
* Находится на стороне Main-thread.
Expand Down Expand Up @@ -72,22 +73,18 @@ export class WorkerStream extends Stream {
}

getCell<T>(path: ModelPath) {
const cell = getOrAdd(this.models, this.pathToStr(path), x => {
return getOrAdd(this.models, this.pathToStr(path), x => {
this.postMessage({
type: WorkerMessageType.Subscribe,
path,
});
return new VersionState({
onExternal: state => this.postMessage({
type: WorkerMessageType.State,
path, state, version: null,
})
});
const vs = new VersionState();
Cell.OnChange(() => vs.localState, e => this.postMessage({
type: WorkerMessageType.State,
path, state: e.value, version: null,
}))
return vs;
});
// cell.on('change', ({value})=>{
//
// })
return cell;
}

protected onDisconnect() {
Expand Down
4 changes: 3 additions & 1 deletion ui/extensions/querySelectorCell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export class QuerySelectorCell<TElement extends Element> extends Cell<TElement>

active() {
super.active();
this.observer.observe(this.element);
this.observer.observe(this.element, {
childList: true
});
}

disactive() {
Expand Down

0 comments on commit 43df9c8

Please sign in to comment.