Skip to content

Commit

Permalink
fix: computed 应该在 inited 之前调用
Browse files Browse the repository at this point in the history
  • Loading branch information
meixg committed Dec 3, 2021
1 parent ae6c698 commit aa21455
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/compilers/renderer-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ export class RendererCompiler {
body.push(...this.emitInitData())
}

// calc computed
for (const name of info.getComputedNames()) {
body.push(ASSIGN(BINARY(I('data'), '[]', L(name)), new ComputedCall(name)))
}

// call inited
if (info.hasMethod('inited')) {
body.push(createTryStatement(
Expand All @@ -82,11 +87,6 @@ export class RendererCompiler {
))
}

// calc computed
for (const name of info.getComputedNames()) {
body.push(ASSIGN(BINARY(I('data'), '[]', L(name)), new ComputedCall(name)))
}

body.push(DEF('html', L('')))
body.push(ASSIGN(I('parentCtx'), I('ctx')))
const aNodeCompiler = new ANodeCompiler(info, !!this.options.ssrOnly, this.id, this.options.useProvidedComponentClass)
Expand Down
10 changes: 10 additions & 0 deletions test/unit/runtime/underscore.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ describe('utils/underscore', function () {
expect(_.createInstanceFromClass(MyComponent)).toHaveProperty('inited')
expect(inited).not.toHaveBeenCalled()
})
it('should not call initData', () => {
const mockFn = jest.fn()
class MyComponent extends Component {
initData () {
mockFn()
}
}
expect(_.createInstanceFromClass(MyComponent)).toHaveProperty('initData')
expect(mockFn).not.toHaveBeenCalled()
})
it('should not call computed', () => {
const foo = jest.fn()
class MyComponent extends Component {
Expand Down

0 comments on commit aa21455

Please sign in to comment.