-
Notifications
You must be signed in to change notification settings - Fork 19
feat: added optional instance setting to allow consumers to choose si… #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: release/1.0.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,11 @@ export interface IOrbViewSettings<N extends INodeBase, E extends IEdgeBase> { | |
export type IOrbViewSettingsInit<N extends INodeBase, E extends IEdgeBase> = Omit< | ||
Partial<IOrbViewSettings<N, E>>, | ||
'render' | ||
> & { render?: Partial<IRendererSettingsInit> }; | ||
> & { render?: Partial<IRendererSettingsInit> } & { | ||
instances: { | ||
simulator?: ISimulator | (() => ISimulator); | ||
}; | ||
}; | ||
|
||
export class OrbView<N extends INodeBase, E extends IEdgeBase> implements IOrbView<N, E, IOrbViewSettings<N, E>> { | ||
private _container: HTMLElement; | ||
|
@@ -150,7 +154,7 @@ export class OrbView<N extends INodeBase, E extends IEdgeBase> implements IOrbVi | |
.on('contextmenu', this.mouseRightClicked) | ||
.on('dblclick.zoom', this.mouseDoubleClicked); | ||
|
||
this._simulator = SimulatorFactory.getSimulator(); | ||
this._simulator = this._createSimulator(settings?.instances?.simulator); | ||
this._simulator.on(SimulatorEventType.SIMULATION_START, () => { | ||
this._isSimulating = true; | ||
this._simulationStartedAt = Date.now(); | ||
|
@@ -569,6 +573,12 @@ export class OrbView<N extends INodeBase, E extends IEdgeBase> implements IOrbVi | |
this._simulator.simulate(); | ||
} | ||
|
||
|
||
private _createSimulator(simulator: ISimulator | (() => ISimulator) | undefined): ISimulator { | ||
if(typeof simulator === "function") return simulator(); | ||
return simulator || SimulatorFactory.getSimulator(); | ||
} | ||
Comment on lines
+577
to
+580
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I think lint is not working for you because this should be indented + if should be wrapped in brackets. Can you check if husky is initialized and Also, there is a cool Typescript trick you can use here: type ICallbackOrInstance<T> = T | (() => T);
export type IOrbViewSettingsInit<N extends INodeBase, E extends IEdgeBase> = Omit<
...
instances?: {
simulator?: ICallbackOrInstance<ISimulator>;
};
}
private _createSimulator(simulator?: ICallbackOrInstance<ISimulator>): ISimulator {
...
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah that definitely looks nicer. is there a cleaner way to do the type check instead of
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that is the most clean way to check for the function. You could have a util function somewhere. Just as I wrote this comment to give you a link to which place is the best to have a utility function in, I found a function: https://github.com/memgraph/orb/blob/main/src/utils/type.utils.ts#L87 You already have |
||
|
||
// TODO: Do we keep these | ||
fixNodes() { | ||
this._simulator.fixNodes(); | ||
|
@@ -579,3 +589,4 @@ export class OrbView<N extends INodeBase, E extends IEdgeBase> implements IOrbVi | |
this._simulator.releaseNodes(); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say that you don't need to join them with
&
- just append to therender
interface. Btwinstances
should be optional, if not users would need to always initiate an empty object even if they don't want to override the simulator instance.