-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(weex): WIP fix flow + handle errors in recycle-list template render
- Loading branch information
Showing
5 changed files
with
44 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 24 additions & 6 deletions
30
src/platforms/weex/runtime/recycle-list/render-component-template.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,35 @@ | ||
/* @flow */ | ||
|
||
import { warn } from 'core/util/debug' | ||
import { handleError } from 'core/util/error' | ||
import { RECYCLE_LIST_MARKER } from 'weex/util/index' | ||
import { createComponentInstanceForVnode } from 'core/vdom/create-component' | ||
|
||
export function isRecyclableComponent (vnode: VNodeWithData): boolean { | ||
return vnode.data.attrs && (RECYCLE_LIST_MARKER in vnode.data.attrs) | ||
return vnode.data.attrs | ||
? (RECYCLE_LIST_MARKER in vnode.data.attrs) | ||
: false | ||
} | ||
|
||
export function renderRecyclableComponentTemplate (vnode: VNodeWithData): VNode { | ||
export function renderRecyclableComponentTemplate (vnode: MountedComponentVNode): VNode { | ||
// TODO: | ||
// 1. adding @isComponentRoot / @componentProps to the root node | ||
// 2. proper error handling | ||
// adding @isComponentRoot / @componentProps to the root node | ||
|
||
// $flow-disable-line | ||
delete vnode.data.attrs[RECYCLE_LIST_MARKER] | ||
const instance = createComponentInstanceForVnode(vnode) | ||
return instance.$options['@render'].call(instance) | ||
const vm = createComponentInstanceForVnode(vnode) | ||
const render = (vm.$options: any)['@render'] | ||
if (render) { | ||
try { | ||
return render.call(vm) | ||
} catch (err) { | ||
handleError(err, vm, `@render`) | ||
} | ||
} else { | ||
warn( | ||
`@render function not defined on component used in <recycle-list>. ` + | ||
`Make sure to declare \`recyclable="true"\` on the component's template.`, | ||
vm | ||
) | ||
} | ||
} |