@@ -128,6 +128,8 @@ define(function (require, exports, module) {
128128 */
129129 var _server ;
130130
131+ let _config = { } ;
132+
131133 /**
132134 * @private
133135 * Determine which live document class should be used for a given document
@@ -375,6 +377,18 @@ define(function (require, exports, module) {
375377 ) ;
376378 }
377379
380+ function _updateVirtualServerScripts ( ) {
381+ if ( ! _server ) {
382+ return ;
383+ }
384+ _server . addVirtualContentAtPath (
385+ `${ _liveDocument . doc . file . parentPath } ${ LiveDevProtocol . LIVE_DEV_REMOTE_SCRIPTS_FILE_NAME } ` ,
386+ _protocol . getRemoteScriptContents ( ) ) ;
387+ _server . addVirtualContentAtPath (
388+ `${ _liveDocument . doc . file . parentPath } ${ LiveDevProtocol . LIVE_DEV_REMOTE_WORKER_SCRIPTS_FILE_NAME } ` ,
389+ PageLoaderWorkerScript ) ;
390+ }
391+
378392 /**
379393 * @private
380394 * Creates the main live document for a given HTML document and notifies the server it exists.
@@ -389,12 +403,7 @@ define(function (require, exports, module) {
389403 return ;
390404 }
391405 _server . add ( _liveDocument ) ;
392- _server . addVirtualContentAtPath (
393- `${ _liveDocument . doc . file . parentPath } ${ LiveDevProtocol . LIVE_DEV_REMOTE_SCRIPTS_FILE_NAME } ` ,
394- _protocol . getRemoteScriptContents ( ) ) ;
395- _server . addVirtualContentAtPath (
396- `${ _liveDocument . doc . file . parentPath } ${ LiveDevProtocol . LIVE_DEV_REMOTE_WORKER_SCRIPTS_FILE_NAME } ` ,
397- PageLoaderWorkerScript ) ;
406+ _updateVirtualServerScripts ( ) ;
398407 }
399408
400409
@@ -649,7 +658,7 @@ define(function (require, exports, module) {
649658 * Initialize the LiveDevelopment module.
650659 */
651660 function init ( config ) {
652- exports . config = config ;
661+ _config = config ;
653662 MainViewManager
654663 . on ( "currentFileChange" , _onFileChange ) ;
655664 DocumentManager
@@ -702,12 +711,29 @@ define(function (require, exports, module) {
702711 /**
703712 * Update configuration in the remote browser
704713 */
705- function updateConfig ( configJSON ) {
714+ function updateConfig ( config ) {
715+ _config = config ;
716+ _updateVirtualServerScripts ( ) ;
717+ refreshConfig ( ) ;
718+ }
719+
720+ /**
721+ * Refresh all live previews with existing configuration in the remote browser
722+ */
723+ function refreshConfig ( ) {
706724 if ( _protocol ) {
707- _protocol . evaluate ( "_LD.updateConfig(" + JSON . stringify ( configJSON ) + ")" ) ;
725+ _protocol . evaluate ( "_LD.updateConfig(" + JSON . stringify ( _config ) + ")" ) ;
708726 }
709727 }
710728
729+ /**
730+ * gets configuration used to set in the remote browser
731+ */
732+ function getConfig ( ) {
733+ // not using structured clone as it's not fast for small objects
734+ return JSON . parse ( JSON . stringify ( _config || { } ) ) ;
735+ }
736+
711737 /**
712738 * Originally unload and reload agents. It doesn't apply for this new implementation.
713739 * @return {jQuery.Promise } Already resolved promise.
@@ -774,7 +800,9 @@ define(function (require, exports, module) {
774800 exports . showHighlight = showHighlight ;
775801 exports . hideHighlight = hideHighlight ;
776802 exports . redrawHighlight = redrawHighlight ;
803+ exports . getConfig = getConfig ;
777804 exports . updateConfig = updateConfig ;
805+ exports . refreshConfig = refreshConfig ;
778806 exports . init = init ;
779807 exports . isActive = isActive ;
780808 exports . setLivePreviewPinned = setLivePreviewPinned ;
0 commit comments