Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
forked fromvuejs/vue

Commitec2bcf8

Browse files
committed
weex rax interop prototype
1 parentbb80d59 commitec2bcf8

File tree

4 files changed

+90
-4
lines changed

4 files changed

+90
-4
lines changed

‎package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
"nightwatch":"^0.9.9",
101101
"nightwatch-helpers":"^1.2.0",
102102
"phantomjs-prebuilt":"^2.1.1",
103+
"rax":"^0.1.2",
103104
"rollup":"^0.36.1",
104105
"rollup-plugin-alias":"^1.2.0",
105106
"rollup-plugin-babel":"^2.4.0",

‎src/platforms/weex/framework.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
importVuefrom'weex/runtime/index'
2-
importrendererfrom'weex/runtime/config'
1+
importVuefrom'./runtime/index'
2+
importrendererfrom'./runtime/config'
3+
importgenRaxRequirefrom'./rax-interop/require'
4+
importgenRaxWrapperfrom'./rax-interop/wrap'
35

46
Vue.weexVersion='__WEEX_VERSION__'
57
export{Vue}
@@ -107,11 +109,16 @@ export function createInstance (
107109
subVue[name]=Vue[name]
108110
})
109111

110-
// The function which create a closure the JS Bundle will run in.
111-
// It will declare some instance variables like `Vue`, HTML5 Timer APIs etc.
112+
// rax interop for require('rax')
113+
// NOTE: need to config rax as external in Webpack
114+
constraxRequire=genRaxRequire(document)
115+
// expose wrapRaxComponent
116+
subVue.wrapRaxComponent=genRaxWrapper(raxRequire('rax'))
117+
112118
constinstanceVars=Object.assign({
113119
Vue:subVue,
114120
weex:weexInstanceVar,
121+
require:raxRequire,
115122
__weex_require_module__:weexInstanceVar.requireModule// deprecated
116123
},timerAPIs)
117124
callFunction(instanceVars,appCode)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
constraxFactory=require('rax/dist/rax.factory')
2+
3+
exportdefaultfunctiongenRaxRequire(document){
4+
constcontext={
5+
document,
6+
__weex_document__:document
7+
}
8+
9+
constmodules={
10+
rax:{
11+
factory:raxFactory.bind(context),
12+
module:{exports:{}},
13+
isInitialized:false
14+
}
15+
}
16+
17+
returnfunctionrequire(name){
18+
varmod=modules[name]
19+
20+
if(mod&&mod.isInitialized){
21+
returnmod.module.exports
22+
}
23+
24+
if(!mod){
25+
thrownewError(
26+
'Requiring unknown module "'+name+'"'
27+
)
28+
}
29+
30+
if(mod.hasError){
31+
thrownewError(
32+
'Requiring module "'+name+'" which threw an exception'
33+
)
34+
}
35+
36+
try{
37+
mod.isInitialized=true
38+
mod.factory(require,mod.module.exports,mod.module)
39+
}catch(e){
40+
mod.hasError=true
41+
mod.isInitialized=false
42+
throwe
43+
}
44+
45+
returnmod.module.exports
46+
}
47+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
exportdefaultfunctiongenRaxWrapper(Rax){
2+
const{ render, createElement, unmountComponentAtNode}=Rax
3+
4+
returnfunctionwrapRaxComponent(RaxComponent){
5+
return{
6+
created(){
7+
constupdate=this._updateFromParent
8+
this._updateFromParent=function(){
9+
update.apply(this,arguments)
10+
this.renderRaxComponent()
11+
}
12+
},
13+
render(h){
14+
returnh('div')
15+
},
16+
mounted(){
17+
this.renderRaxComponent()
18+
},
19+
beforeDestroy(){
20+
unmountComponentAtNode(this.$el)
21+
},
22+
methods:{
23+
renderRaxComponent(){
24+
constdata=this.$vnode.data
25+
constprops=Object.assign({},data.attrs,data.domProps,data.props)
26+
render(createElement(RaxComponent,props),this.$el)
27+
}
28+
}
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp