File tree Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change @@ -65,6 +65,31 @@ ViewModel.transition = function (id, transition) {
65
65
return this
66
66
}
67
67
68
+ /**
69
+ * Expose internal modules for plugins
70
+ */
71
+ ViewModel . require = function ( path ) {
72
+ return require ( './' + path )
73
+ }
74
+
75
+ /**
76
+ * Expose an interface for plugins
77
+ */
78
+ ViewModel . use = function ( plugin ) {
79
+ if ( typeof plugin === 'string' ) {
80
+ try {
81
+ plugin = require ( plugin )
82
+ } catch ( e ) {
83
+ return utils . warn ( 'Cannot find plugin: ' + plugin )
84
+ }
85
+ }
86
+ if ( typeof plugin === 'function' ) {
87
+ plugin ( ViewModel )
88
+ } else if ( plugin . install ) {
89
+ plugin . install ( ViewModel )
90
+ }
91
+ }
92
+
68
93
ViewModel . extend = extend
69
94
ViewModel . nextTick = utils . nextTick
70
95
Original file line number Diff line number Diff line change @@ -37,6 +37,40 @@ describe('UNIT: API', function () {
37
37
38
38
} )
39
39
40
+ describe ( 'require()' , function ( ) {
41
+
42
+ it ( 'should expose internal modules' , function ( ) {
43
+ var c = Vue . require ( 'config' ) ,
44
+ cc = require ( 'vue/src/config' )
45
+ assert . strictEqual ( c , cc )
46
+ } )
47
+
48
+ } )
49
+
50
+ describe ( 'use()' , function ( ) {
51
+
52
+ it ( 'should install a plugin via its install function' , function ( ) {
53
+ var called = false
54
+ Vue . use ( {
55
+ install : function ( vue ) {
56
+ called = true
57
+ assert . strictEqual ( vue , Vue )
58
+ }
59
+ } )
60
+ assert . ok ( called )
61
+ } )
62
+
63
+ it ( 'should install a plugin if its a function itself' , function ( ) {
64
+ var called = false
65
+ Vue . use ( function ( vue ) {
66
+ called = true
67
+ assert . strictEqual ( vue , Vue )
68
+ } )
69
+ assert . ok ( called )
70
+ } )
71
+
72
+ } )
73
+
40
74
describe ( 'filter()' , function ( ) {
41
75
42
76
var reverse = function ( input ) {
You can’t perform that action at this time.
0 commit comments