@@ -111,10 +111,13 @@ class Base {
111111 /**
112112 * Remote method access for other threads. Example use case:
113113 * remote: {app: ['myRemoteMethod']}
114- * @member {Object|null} remote=null
114+ *
115+ * ONLY supported for singletons.
116+ *
117+ * @member {Object|null} remote_=null
115118 * @protected
116119 */
117- remote : null
120+ remote_ : null
118121 }
119122
120123 /**
@@ -281,6 +284,24 @@ class Base {
281284 return value
282285 }
283286
287+ /**
288+ * Triggered before the remote config gets changed
289+ * @param {Object|null } value
290+ * @param {Object|null } oldValue
291+ * @returns {Object|null }
292+ * @protected
293+ */
294+ beforeSetRemote ( value , oldValue ) {
295+ let me = this ;
296+
297+ // Only allow remote access for singletons or main thread addons
298+ if ( value && ! me . singleton && ! me . isMainThreadAddon ) {
299+ throw new Error ( 'Remote method access is only functional for Singleton classes ' + me . className )
300+ }
301+
302+ return value
303+ }
304+
284305 /**
285306 * @param {String } fn The name of a function to find in the passed scope object.
286307 * @param {Object } originName The name of the method inside the originScope.
@@ -431,19 +452,14 @@ class Base {
431452 * @protected
432453 */
433454 initRemote ( ) {
434- let me = this ,
435- { className, remote} = me ,
455+ let { className, remote} = this ,
436456 { currentWorker} = Neo ;
437457
438- if ( ! me . singleton && ! me . isMainThreadAddon ) {
439- throw new Error ( 'Remote method access is only functional for Singleton classes ' + className )
440- }
441-
442458 if ( ! Neo . config . unitTestMode ) {
443459 if ( Neo . workerId !== 'main' && currentWorker . isSharedWorker && ! currentWorker . isConnected ) {
444460 currentWorker . on ( 'connected' , ( ) => {
445461 Base . sendRemotes ( className , remote )
446- } , me , { once : true } )
462+ } , this , { once : true } )
447463 } else {
448464 Base . sendRemotes ( className , remote )
449465 }
0 commit comments