File tree Expand file tree Collapse file tree 4 files changed +90
-4
lines changed Expand file tree Collapse file tree 4 files changed +90
-4
lines changed Original file line number Diff line number Diff line change 100
100
"nightwatch" : " ^0.9.9" ,
101
101
"nightwatch-helpers" : " ^1.2.0" ,
102
102
"phantomjs-prebuilt" : " ^2.1.1" ,
103
+ "rax" : " ^0.1.2" ,
103
104
"rollup" : " ^0.36.1" ,
104
105
"rollup-plugin-alias" : " ^1.2.0" ,
105
106
"rollup-plugin-babel" : " ^2.4.0" ,
Original file line number Diff line number Diff line change 1
- import Vue from 'weex/runtime/index'
2
- import renderer from 'weex/runtime/config'
1
+ import Vue from './runtime/index'
2
+ import renderer from './runtime/config'
3
+ import genRaxRequire from './rax-interop/require'
4
+ import genRaxWrapper from './rax-interop/wrap'
3
5
4
6
Vue . weexVersion = '__WEEX_VERSION__'
5
7
export { Vue }
@@ -107,11 +109,16 @@ export function createInstance (
107
109
subVue [ name ] = Vue [ name ]
108
110
} )
109
111
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
+ const raxRequire = genRaxRequire ( document )
115
+ // expose wrapRaxComponent
116
+ subVue . wrapRaxComponent = genRaxWrapper ( raxRequire ( 'rax' ) )
117
+
112
118
const instanceVars = Object . assign ( {
113
119
Vue : subVue ,
114
120
weex : weexInstanceVar ,
121
+ require : raxRequire ,
115
122
__weex_require_module__ : weexInstanceVar . requireModule // deprecated
116
123
} , timerAPIs )
117
124
callFunction ( instanceVars , appCode )
Original file line number Diff line number Diff line change
1
+ const raxFactory = require ( 'rax/dist/rax.factory' )
2
+
3
+ export default function genRaxRequire ( document ) {
4
+ const context = {
5
+ document,
6
+ __weex_document__ : document
7
+ }
8
+
9
+ const modules = {
10
+ rax : {
11
+ factory : raxFactory . bind ( context ) ,
12
+ module : { exports : { } } ,
13
+ isInitialized : false
14
+ }
15
+ }
16
+
17
+ return function require ( name ) {
18
+ var mod = modules [ name ]
19
+
20
+ if ( mod && mod . isInitialized ) {
21
+ return mod . module . exports
22
+ }
23
+
24
+ if ( ! mod ) {
25
+ throw new Error (
26
+ 'Requiring unknown module "' + name + '"'
27
+ )
28
+ }
29
+
30
+ if ( mod . hasError ) {
31
+ throw new Error (
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
+ throw e
43
+ }
44
+
45
+ return mod . module . exports
46
+ }
47
+ }
Original file line number Diff line number Diff line change
1
+ export default function genRaxWrapper ( Rax ) {
2
+ const { render, createElement, unmountComponentAtNode } = Rax
3
+
4
+ return function wrapRaxComponent ( RaxComponent ) {
5
+ return {
6
+ created ( ) {
7
+ const update = this . _updateFromParent
8
+ this . _updateFromParent = function ( ) {
9
+ update . apply ( this , arguments )
10
+ this . renderRaxComponent ( )
11
+ }
12
+ } ,
13
+ render ( h ) {
14
+ return h ( 'div' )
15
+ } ,
16
+ mounted ( ) {
17
+ this . renderRaxComponent ( )
18
+ } ,
19
+ beforeDestroy ( ) {
20
+ unmountComponentAtNode ( this . $el )
21
+ } ,
22
+ methods : {
23
+ renderRaxComponent ( ) {
24
+ const data = this . $vnode . data
25
+ const props = Object . assign ( { } , data . attrs , data . domProps , data . props )
26
+ render ( createElement ( RaxComponent , props ) , this . $el )
27
+ }
28
+ }
29
+ }
30
+ }
31
+ }
You can’t perform that action at this time.
0 commit comments