Skip to content

Commit c12659e

Browse files
committed
feat: add impure pipe for ordeting inputs, outputs, etc
Replaces keyvalue pipe with new keyvalueimpure pipe to ensure proper reordering update when their order changes dynamically. Users with custom templates need to update | keyvalue: to | keyvalueimpure: in their templates and import the new pipe
1 parent 35c8420 commit c12659e

File tree

11 files changed

+53
-13
lines changed

11 files changed

+53
-13
lines changed

ng16/patch/module.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { SocketComponent } from './presets/classic/components/socket/socket.comp
77
import { ConnectionWrapperComponent } from './presets/classic/components/connection/connection-wrapper.component';
88
import { ControlComponent } from './presets/classic/components/control/control.component';
99
import { RefDirective } from './ref';
10+
import { ImpureKeyvaluePipe } from './shared/pipes/impure-keyvalue.pipe';
1011

1112
@NgModule({
1213
declarations: [
@@ -15,7 +16,8 @@ import { RefDirective } from './ref';
1516
ConnectionComponent,
1617
ConnectionWrapperComponent,
1718
SocketComponent,
18-
ControlComponent
19+
ControlComponent,
20+
ImpureKeyvaluePipe
1921
],
2022
imports: [
2123
CommonModule
@@ -26,7 +28,8 @@ import { RefDirective } from './ref';
2628
ConnectionComponent,
2729
ConnectionWrapperComponent,
2830
SocketComponent,
29-
ControlComponent
31+
ControlComponent,
32+
ImpureKeyvaluePipe
3033
]
3134
})
3235
export class ReteModule { }

ng17/patch/module.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { SocketComponent } from './presets/classic/components/socket/socket.comp
77
import { ConnectionWrapperComponent } from './presets/classic/components/connection/connection-wrapper.component';
88
import { ControlComponent } from './presets/classic/components/control/control.component';
99
import { RefDirective } from './ref';
10+
import { ImpureKeyvaluePipe } from './shared/pipes/impure-keyvalue.pipe';
1011

1112
@NgModule({
1213
declarations: [
@@ -15,7 +16,8 @@ import { RefDirective } from './ref';
1516
ConnectionComponent,
1617
ConnectionWrapperComponent,
1718
SocketComponent,
18-
ControlComponent
19+
ControlComponent,
20+
ImpureKeyvaluePipe
1921
],
2022
imports: [
2123
CommonModule
@@ -26,7 +28,8 @@ import { RefDirective } from './ref';
2628
ConnectionComponent,
2729
ConnectionWrapperComponent,
2830
SocketComponent,
29-
ControlComponent
31+
ControlComponent,
32+
ImpureKeyvaluePipe
3033
]
3134
})
3235
export class ReteModule { }

ng18/patch/module.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { SocketComponent } from './presets/classic/components/socket/socket.comp
77
import { ConnectionWrapperComponent } from './presets/classic/components/connection/connection-wrapper.component';
88
import { ControlComponent } from './presets/classic/components/control/control.component';
99
import { RefDirective } from './ref';
10+
import { ImpureKeyvaluePipe } from './shared/pipes/impure-keyvalue.pipe';
1011

1112
@NgModule({
1213
declarations: [
@@ -15,7 +16,8 @@ import { RefDirective } from './ref';
1516
ConnectionComponent,
1617
ConnectionWrapperComponent,
1718
SocketComponent,
18-
ControlComponent
19+
ControlComponent,
20+
ImpureKeyvaluePipe
1921
],
2022
imports: [
2123
CommonModule
@@ -26,7 +28,8 @@ import { RefDirective } from './ref';
2628
ConnectionComponent,
2729
ConnectionWrapperComponent,
2830
SocketComponent,
29-
ControlComponent
31+
ControlComponent,
32+
ImpureKeyvaluePipe
3033
]
3134
})
3235
export class ReteModule { }
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// [imports]
22
import { CommonModule } from '@angular/common';
33
import { RefDirective } from '../../../../ref';
4+
import { ImpureKeyvaluePipe } from '../../../../shared/pipes/impure-keyvalue.pipe';
45
// [component-directive]
5-
imports: [CommonModule, RefDirective],
6+
imports: [CommonModule, RefDirective, ImpureKeyvaluePipe],
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// [imports]
22
import { CommonModule } from '@angular/common';
33
import { RefDirective } from '../../../../ref';
4+
import { ImpureKeyvaluePipe } from '../../../../shared/pipes/impure-keyvalue.pipe';
45
// [component-directive]
5-
imports: [CommonModule, RefDirective],
6+
imports: [CommonModule, RefDirective, ImpureKeyvaluePipe],

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ export * from './presets/classic/components'
1010
export * from './presets/context-menu/components'
1111
export * from './presets/minimap/components'
1212
export * from './presets/reroute/components'
13+
export * from './shared/pipes'
1314
export * from './ref'
1415
export * from './core'

src/module.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { SocketComponent } from './presets/classic/components/socket/socket.comp
77
import { ConnectionWrapperComponent } from './presets/classic/components/connection/connection-wrapper.component';
88
import { ControlComponent } from './presets/classic/components/control/control.component';
99
import { RefDirective } from './ref';
10+
import { ImpureKeyvaluePipe } from './shared/pipes/impure-keyvalue.pipe';
1011

1112
@NgModule({
1213
declarations: [
@@ -15,7 +16,8 @@ import { RefDirective } from './ref';
1516
ConnectionComponent,
1617
ConnectionWrapperComponent,
1718
SocketComponent,
18-
ControlComponent
19+
ControlComponent,
20+
ImpureKeyvaluePipe
1921
],
2022
imports: [
2123
CommonModule
@@ -26,7 +28,8 @@ import { RefDirective } from './ref';
2628
ConnectionComponent,
2729
ConnectionWrapperComponent,
2830
SocketComponent,
29-
ControlComponent
31+
ControlComponent,
32+
ImpureKeyvaluePipe
3033
],
3134
entryComponents: [
3235
NodeComponent,

src/presets/classic/components/node/node.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="title" data-testid="title">{{data.label}}</div>
2-
<div class="output" *ngFor="let output of data.outputs | keyvalue: sortByIndex" [attr.data-testid]="'output-'+output.key">
2+
<div class="output" *ngFor="let output of data.outputs | keyvalueimpure: sortByIndex" [attr.data-testid]="'output-'+output.key">
33
<div class="output-title" data-testid="output-title">{{output.value?.label}}</div>
44
<div
55
class="output-socket"
@@ -11,13 +11,13 @@
1111
</div>
1212
<div
1313
class="control"
14-
*ngFor="let control of data.controls | keyvalue: sortByIndex"
14+
*ngFor="let control of data.controls | keyvalueimpure: sortByIndex"
1515
refComponent
1616
[data]="{type: 'control', payload: control.value }"
1717
[emit]="emit"
1818
[attr.data-testid]="'control-'+control.key"
1919
></div>
20-
<div class="input" *ngFor="let input of data.inputs | keyvalue: sortByIndex" [attr.data-testid]="'input-'+input.key">
20+
<div class="input" *ngFor="let input of data.inputs | keyvalueimpure: sortByIndex" [attr.data-testid]="'input-'+input.key">
2121
<div
2222
class="input-socket"
2323
refComponent

src/shared/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './drag';
2+
export * from './pipes';
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { Pipe, PipeTransform } from '@angular/core';
2+
3+
@Pipe({
4+
name: 'keyvalueimpure',
5+
pure: false
6+
})
7+
export class ImpureKeyvaluePipe implements PipeTransform {
8+
9+
transform(value: {[key: string]: any} | null | undefined, compareFn?: (a: any, b: any) => number): Array<{key: string, value: any}> {
10+
if (!value || typeof value !== 'object') {
11+
return [];
12+
}
13+
14+
const result = Object.entries(value).map(([key, val]) => ({key, value: val}));
15+
16+
if (compareFn) {
17+
result.sort(compareFn);
18+
}
19+
20+
return result;
21+
}
22+
}

0 commit comments

Comments
 (0)