@@ -11,10 +11,10 @@ function socketMixin(service) {
1111
1212 service . mixin ( {
1313 setup ( app , path ) {
14- if ( ! this . _socketSetup ) {
14+ if ( ! this . _socketSetup ) {
1515 const info = app . _socketInfo ;
16- const mountpath = ( app . mountpath !== '/' && typeof app . mountpath === 'string' ) ?
17- app . mountpath : '' ;
16+ const isSubApp = app . mountpath !== '/' && typeof app . mountpath === 'string' ;
17+ const mountpath = isSubApp ? app . mountpath : '' ;
1818 const fullPath = stripSlashes ( `${ mountpath } /${ path } ` ) ;
1919 const setupSocket = socket => {
2020 setupMethodHandlers . call ( app , info , socket , fullPath , this ) ;
@@ -41,22 +41,26 @@ function socketMixin(service) {
4141 } ) ;
4242}
4343
44- export default function mixin ( ) {
45- const app = this ;
44+ export default function createMixin ( property ) {
45+ return function mixin ( ) {
46+ const app = this ;
4647
47- app . mixins . push ( socketMixin ) ;
48- app . mixins . push ( filterMixin ) ;
48+ app . mixins . push ( socketMixin ) ;
49+ app . mixins . push ( filterMixin ) ;
4950
50- // When mounted as a sub-app, override the parent setup so you don't have to call it
51- app . on ( 'mount' , parent => {
52- const oldSetup = parent . setup ;
51+ // When mounted as a sub-app, override the parent setup to call our
52+ // own setup so the developer doesn't need to call it explicitly.
53+ app . on ( 'mount' , parent => {
54+ const oldSetup = parent . setup ;
5355
54- parent . setup = function ( ... args ) {
55- const result = oldSetup . apply ( this , args ) ;
56- app . setup ( ... args ) ;
57- return result ;
58- } ;
59- } ) ;
56+ parent . setup = function ( ... args ) {
57+ const result = oldSetup . apply ( this , args ) ;
58+ app [ property ] = parent [ property ] ;
59+ app . setup ( ... args ) ;
60+ return result ;
61+ } ;
62+ } ) ;
63+ } ;
6064}
6165
62- mixin . socketMixin = socketMixin ;
66+ createMixin . socketMixin = socketMixin ;
0 commit comments