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) {
6565 return this
6666}
6767
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+
6893ViewModel . extend = extend
6994ViewModel . nextTick = utils . nextTick
7095
Original file line number Diff line number Diff line change @@ -37,6 +37,40 @@ describe('UNIT: API', function () {
3737
3838 } )
3939
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+
4074 describe ( 'filter()' , function ( ) {
4175
4276 var reverse = function ( input ) {
You can’t perform that action at this time.
0 commit comments