Skip to content

Commit 34c91e7

Browse files
committed
more internal improvements to input fields
1 parent aa36c43 commit 34c91e7

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

packages/core/src/fields/inputFields/AbstractInputField.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export abstract class AbstractInputField<
2727
this.svelteWrapper = new InputFieldSvelteWrapper<ComponentValueType, SvelteExports>(
2828
this.plugin,
2929
this.getSvelteComponent(),
30+
value => this.notifySubscription(this.mapValue(value)),
3031
);
3132

3233
this.inputSignal = new MappedSignal<unknown, MetadataValueType>(
@@ -137,12 +138,6 @@ export abstract class AbstractInputField<
137138
callback: value => this.svelteWrapper.setValue(this.reverseMapValue(value)),
138139
});
139140

140-
this.svelteWrapper.registerListener({
141-
callback: value => {
142-
this.notifySubscription(this.mapValue(value));
143-
},
144-
});
145-
146141
const bindTarget = this.mountable.getBindTarget();
147142

148143
if (bindTarget) {

packages/core/src/fields/inputFields/InputFieldSvelteWrapper.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import type { IPlugin } from 'packages/core/src/IPlugin';
2-
import type { Listener } from 'packages/core/src/utils/Signal';
3-
import { Notifier } from 'packages/core/src/utils/Signal';
42
import type { Component as SvelteComponent } from 'svelte';
53
import { mount, unmount } from 'svelte';
64

@@ -21,19 +19,23 @@ export interface InputFieldSvelteProps<Value> {
2119
onValueChange: (value: Value) => void;
2220
}
2321

24-
export class InputFieldSvelteWrapper<Value, SvelteExports = object> extends Notifier<Value, Listener<Value>> {
22+
export class InputFieldSvelteWrapper<Value, SvelteExports = object> {
2523
readonly plugin: IPlugin;
2624
private readonly svelteComponent: InputFieldSvelteComponent<Value, SvelteExports>;
2725
private svelteComponentInstance?: ReturnType<InputFieldSvelteComponent<Value, SvelteExports>>;
2826
private mounted: boolean;
27+
private onValueChange: (value: Value) => void;
2928

30-
constructor(plugin: IPlugin, svelteComponent: InputFieldSvelteComponent<Value, SvelteExports>) {
31-
super();
32-
29+
constructor(
30+
plugin: IPlugin,
31+
svelteComponent: InputFieldSvelteComponent<Value, SvelteExports>,
32+
onValueChange: (value: Value) => void,
33+
) {
3334
this.plugin = plugin;
3435

3536
this.mounted = false;
3637
this.svelteComponent = svelteComponent;
38+
this.onValueChange = onValueChange;
3739
}
3840

3941
/**
@@ -62,9 +64,7 @@ export class InputFieldSvelteWrapper<Value, SvelteExports = object> extends Noti
6264
{
6365
plugin: this.plugin,
6466
value: initialValue,
65-
onValueChange: (value: Value) => {
66-
this.notifyListeners(value);
67-
},
67+
onValueChange: this.onValueChange,
6868
},
6969
mountArgs,
7070
);
@@ -81,7 +81,6 @@ export class InputFieldSvelteWrapper<Value, SvelteExports = object> extends Noti
8181
* This unmounts the component.
8282
*/
8383
public unmount(): void {
84-
this.unregisterAllListeners();
8584
if (this.svelteComponentInstance) {
8685
unmount(this.svelteComponentInstance);
8786
}

0 commit comments

Comments
 (0)