Skip to content

Commit c9c10b5

Browse files
committed
refactor(dev-app): convert to zoneless app
1 parent 8e054fc commit c9c10b5

6 files changed

Lines changed: 92 additions & 52 deletions

File tree

angular.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@
6363
"outputPath": "dist/dev-app",
6464
"index": "projects/dev-app/src/index.html",
6565
"browser": "projects/dev-app/src/main.ts",
66-
"polyfills": [
67-
"zone.js"
68-
],
6966
"tsConfig": "projects/dev-app/tsconfig.app.json",
7067
"inlineStyleLanguage": "scss",
7168
"assets": [
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
import { ApplicationConfig } from '@angular/core';
1+
import {
2+
ApplicationConfig,
3+
provideBrowserGlobalErrorListeners,
4+
provideZonelessChangeDetection,
5+
} from '@angular/core';
26
import { provideRouter } from '@angular/router';
37

48
import { routes } from './app.routes';
59

610
export const appConfig: ApplicationConfig = {
7-
providers: [provideRouter(routes)],
11+
providers: [
12+
provideBrowserGlobalErrorListeners(),
13+
provideZonelessChangeDetection(),
14+
provideRouter(routes),
15+
],
816
};

projects/dev-app/src/app/diff/diff.html

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,19 @@
44
[(ngModel)]="value"
55
(originalValueChange)="log($event)"
66
(modifiedValueChange)="log($event)"
7-
[orientation]="orientation"
8-
[revertControls]="revertControls"
9-
[highlightChanges]="highlightChanges"
10-
[gutter]="gutter"
11-
[disabled]="disabled"
7+
[orientation]="orientation()"
8+
[revertControls]="revertControls()"
9+
[highlightChanges]="highlightChanges()"
10+
[gutter]="gutter()"
11+
[disabled]="disabled()"
1212
/>
1313

14-
<button (click)="doc = '123'">change original value</button>
15-
<button (click)="doc2 = '13\n456'">change modified value</button>
16-
<button (click)="orientation === 'a-b' ? (orientation = 'b-a') : (orientation = 'a-b')">
17-
orientation
18-
</button>
19-
<button
20-
(click)="revertControls === 'a-to-b' ? (revertControls = 'b-to-a') : (revertControls = 'a-to-b')"
21-
>
22-
revertControls
23-
</button>
24-
<button (click)="highlightChanges = !highlightChanges">highlightChanges</button>
25-
<button (click)="gutter = !gutter">gutter</button>
26-
<button (click)="disabled = !disabled">disabled</button>
14+
<button (click)="setOriginalValue()">change original value</button>
15+
<button (click)="setModifiedValue()">change modified value</button>
16+
<button (click)="setOrientation()">orientation</button>
17+
<button (click)="setRevertControls()">revertControls</button>
18+
<button (click)="setHighlightChanges()">highlightChanges</button>
19+
<button (click)="setGutter()">gutter</button>
20+
<button (click)="setDisabled()">disabled</button>
2721

28-
<code-editor [value]="doc2" [extensions]="unifiedExts" />
22+
<code-editor [value]="doc2()" [extensions]="unifiedExts" />
Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { CodeEditor, DiffEditor, Orientation, RevertControls, Setup } from '@acrodata/code-editor';
2-
import { Component } from '@angular/core';
2+
import { Component, linkedSignal, signal } from '@angular/core';
33
import { FormControl, FormsModule, ReactiveFormsModule } from '@angular/forms';
44
import { unifiedMergeView } from '@codemirror/merge';
55

@@ -10,36 +10,72 @@ import { unifiedMergeView } from '@codemirror/merge';
1010
styleUrl: './diff.scss',
1111
})
1212
export class Diff {
13-
doc = `one
13+
doc = signal(`one
1414
two
1515
three
1616
four
17-
five`;
17+
five`);
1818

19-
doc2 = this.doc.replace(/t/g, 'T') + '\nSix';
19+
doc2 = signal(this.doc().replace(/t/g, 'T') + '\nSix');
2020

21-
value = {
22-
original: this.doc,
23-
modified: this.doc2,
24-
};
21+
value = linkedSignal(() => ({
22+
original: this.doc(),
23+
modified: this.doc2(),
24+
}));
2525

2626
control = new FormControl({ value: this.value, disabled: true });
2727

2828
unifiedExts = [
2929
unifiedMergeView({
30-
original: this.doc,
30+
original: this.doc(),
3131
gutter: true,
3232
}),
3333
];
3434

3535
setup: Setup = 'minimal';
36-
orientation: Orientation = 'a-b';
37-
revertControls: RevertControls = 'a-to-b';
38-
highlightChanges = true;
39-
gutter = true;
40-
disabled = false;
36+
orientation = signal<Orientation>('a-b');
37+
revertControls = signal<RevertControls>('a-to-b');
38+
highlightChanges = signal(true);
39+
gutter = signal(true);
40+
disabled = signal(false);
4141

4242
log(e: any) {
4343
console.log(e);
4444
}
45+
46+
setOriginalValue() {
47+
this.doc.set('123');
48+
}
49+
50+
setModifiedValue() {
51+
this.doc2.set('13\n456');
52+
}
53+
54+
setOrientation() {
55+
if (this.orientation() === 'a-b') {
56+
this.orientation.set('b-a');
57+
} else {
58+
this.orientation.set('a-b');
59+
}
60+
}
61+
62+
setRevertControls() {
63+
if (this.revertControls() === 'a-to-b') {
64+
this.revertControls.set('b-to-a');
65+
} else {
66+
this.revertControls.set('a-to-b');
67+
}
68+
}
69+
70+
setHighlightChanges() {
71+
this.highlightChanges.update(v => !v);
72+
}
73+
74+
setGutter() {
75+
this.gutter.update(v => !v);
76+
}
77+
78+
setDisabled() {
79+
this.disabled.update(v => !v);
80+
}
4581
}

projects/dev-app/src/app/home/home.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ <h4>Code Editor Config</h4>
88

99
<div>
1010
<h4>
11-
<button matButton (click)="showOutput = !showOutput">Toggle output</button>
11+
<button matButton (click)="toggleOutput()">Toggle output</button>
1212
</h4>
1313
<div class="editor-wrap">
1414
<code-editor
@@ -29,7 +29,7 @@ <h4>
2929
[languages]="languages"
3030
/>
3131

32-
@if (showOutput) {
32+
@if (showOutput()) {
3333
<textarea [style.height]="'500px'" [(ngModel)]="code"></textarea>
3434
}
3535
</div>
@@ -38,7 +38,7 @@ <h4>Unified diff-editor</h4>
3838
<code-editor
3939
#editor
4040
[style.height]="'500px'"
41-
[value]="modifiedCode"
41+
[value]="modifiedCode()"
4242
[theme]="options.theme"
4343
[setup]="options.setup"
4444
[readonly]="options.readonly"
@@ -65,8 +65,8 @@ <h4>Split diff-editor</h4>
6565
<diff-editor
6666
#editor
6767
[style.height]="'100vh'"
68-
[originalValue]="originalCode"
69-
[modifiedValue]="modifiedCode"
68+
[originalValue]="originalCode()"
69+
[modifiedValue]="modifiedCode()"
7070
[orientation]="options2.orientation"
7171
[revertControls]="options2.revertControls"
7272
[highlightChanges]="options2.highlightChanges"

projects/dev-app/src/app/home/home.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AfterViewInit, Component, DestroyRef, OnInit, inject } from '@angular/core';
1+
import { AfterViewInit, Component, DestroyRef, OnInit, inject, signal } from '@angular/core';
22
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
33
import { FormGroup, FormsModule, ReactiveFormsModule } from '@angular/forms';
44
import { MatButtonModule } from '@angular/material/button';
@@ -89,9 +89,9 @@ export class Home implements OnInit, AfterViewInit {
8989
highlightWhitespace: false,
9090
};
9191

92-
code = '';
92+
code = signal('');
9393

94-
showOutput = false;
94+
showOutput = signal(false);
9595

9696
ngOnInit(): void {
9797
this.getLangSample('javascript');
@@ -110,9 +110,10 @@ export class Home implements OnInit, AfterViewInit {
110110
getLangSample(lang: string) {
111111
fetch(`lang_samples/${lang}.txt`).then(async response => {
112112
if (response.ok) {
113-
this.code = await response.text();
113+
const text = await response.text();
114+
this.code.set(text);
114115
} else {
115-
this.code = '';
116+
this.code.set('');
116117
}
117118
});
118119
}
@@ -121,16 +122,16 @@ export class Home implements OnInit, AfterViewInit {
121122
console.log(e);
122123
}
123124

124-
originalCode = `one
125+
originalCode = signal(`one
125126
two
126127
three
127128
four
128-
five`;
129-
modifiedCode = this.originalCode.replace(/t/g, 'T') + '\nSix';
129+
five`);
130+
modifiedCode = signal(this.originalCode().replace(/t/g, 'T') + '\nSix');
130131

131132
unifiedExts = [
132133
unifiedMergeView({
133-
original: this.originalCode,
134+
original: this.originalCode(),
134135
}),
135136
];
136137

@@ -168,4 +169,8 @@ five`;
168169
highlightChanges: true,
169170
gutter: true,
170171
};
172+
173+
toggleOutput() {
174+
this.showOutput.update(v => !v);
175+
}
171176
}

0 commit comments

Comments
 (0)