Skip to content

Commit a57b3c8

Browse files
committed
prettier + fix test
1 parent 914cc77 commit a57b3c8

File tree

6 files changed

+33
-28
lines changed

6 files changed

+33
-28
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/runtime/reactivity/computations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { batched } from "../utils";
22

3-
export interface ReactiveValue<TRead, TWrite=TRead> {
3+
export interface ReactiveValue<TRead, TWrite = TRead> {
44
(): TRead;
55
/**
66
* Update the value of the reactive with a new value. If the new value is different

src/runtime/reactivity/computed.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ interface ComputedOptions<TWrite> {
1111
set?(value: TWrite): void;
1212
}
1313

14-
export function computed<TRead, TWrite=TRead>(getter: () => TRead, options: ComputedOptions<TWrite> = {}): ReactiveValue<TRead, TWrite> {
14+
export function computed<TRead, TWrite = TRead>(
15+
getter: () => TRead,
16+
options: ComputedOptions<TWrite> = {}
17+
): ReactiveValue<TRead, TWrite> {
1518
const computation = createComputation({
1619
compute: () => {
1720
onWriteAtom(computation);

tests/components/__snapshots__/error_handling.test.ts.snap

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ exports[`basics render from above on error -- handler is not a Root or MountFibe
100100
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
101101
const comp1 = app.createComponent(\`Parent\`, true, false, false, []);
102102

103-
return function template(ctx, node, key = \\"\\") {
103+
return function template(ctx, node, key = "") {
104104
return comp1({}, key + \`__1\`, node, this, null);
105105
}
106106
}"
@@ -114,12 +114,12 @@ exports[`basics render from above on error -- handler is not a Root or MountFibe
114114

115115
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
116116

117-
return function template(ctx, node, key = \\"\\") {
117+
return function template(ctx, node, key = "") {
118118
let b2, b3;
119-
if (ctx['error']) {
119+
if (ctx['this'].error) {
120120
b2 = text(\`Error\`);
121121
} else {
122-
b3 = comp1({onError: (ctx['handleError']).bind(this)}, key + \`__1\`, node, this, null);
122+
b3 = comp1({onError: (ctx['this'].handleError).bind(this)}, key + \`__1\`, node, this, null);
123123
}
124124
return block1([], [b2, b3]);
125125
}
@@ -130,12 +130,13 @@ exports[`basics render from above on error -- handler is not a Root or MountFibe
130130
"function anonymous(app, bdom, helpers
131131
) {
132132
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
133+
let { safeOutput } = helpers;
133134

134-
let block1 = createBlock(\`<div><block-text-0/></div>\`);
135+
let block1 = createBlock(\`<div><block-child-0/></div>\`);
135136

136-
return function template(ctx, node, key = \\"\\") {
137-
let txt1 = ctx['a'].b.c;
138-
return block1([txt1]);
137+
return function template(ctx, node, key = "") {
138+
const b2 = safeOutput(ctx['a'].b.c);
139+
return block1([], [b2]);
139140
}
140141
}"
141142
`;

tests/components/error_handling.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { App, Component, mount, onWillDestroy, props } from "../../src";
1+
import { App, Component, mount, onWillDestroy, props, types } from "../../src";
22
import { OwlError } from "../../src/common/owl_error";
33
import {
44
onError,
@@ -239,7 +239,8 @@ function(app, bdom, helpers) {
239239

240240
test("render from above on error -- handler is not a Root or MountFiber", async () => {
241241
class Boom extends Component {
242-
static template = xml`<div t-esc="a.b.c"/>`;
242+
static template = xml`<div t-out="a.b.c"/>`;
243+
props = props({ onError: types.function() });
243244
setup() {
244245
onError((err) => {
245246
this.props.onError(err);
@@ -250,9 +251,9 @@ function(app, bdom, helpers) {
250251
class Parent extends Component {
251252
static template = xml`
252253
<div>
253-
<t t-if="error">Error</t>
254+
<t t-if="this.error">Error</t>
254255
<t t-else="">
255-
<Boom onError.bind="handleError"/>
256+
<Boom onError.bind="this.handleError"/>
256257
</t>
257258
</div>`;
258259
static components = { Boom };
@@ -261,7 +262,7 @@ function(app, bdom, helpers) {
261262

262263
handleError(err: Error) {
263264
this.error = err;
264-
this.render();
265+
render(this);
265266
}
266267
}
267268

tests/reactivity/computed.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -391,21 +391,21 @@ describe("writable computed", () => {
391391
const value = signal(4);
392392
const binary = computed(() => value().toString(2), {
393393
set: (nextValue: string | number) => {
394-
if(typeof nextValue === "number") {
395-
value.set(nextValue)
394+
if (typeof nextValue === "number") {
395+
value.set(nextValue);
396396
} else {
397-
value.set(parseInt(nextValue, 2))
397+
value.set(parseInt(nextValue, 2));
398398
}
399-
}
400-
})
401-
expect(binary()).toBe("100")
399+
},
400+
});
401+
expect(binary()).toBe("100");
402402

403403
// can set a string
404-
binary.set("110")
405-
expect(value()).toBe(6)
404+
binary.set("110");
405+
expect(value()).toBe(6);
406406

407407
// can also set a number
408-
binary.set(7)
409-
expect(value()).toBe(7)
410-
})
408+
binary.set(7);
409+
expect(value()).toBe(7);
410+
});
411411
});

0 commit comments

Comments
 (0)