CCALI / a2jauthor

CALI A2JAuthor document automation authoring and viewing platform
https://www.a2jauthor.org
Other
4 stars 1 forks source link

Saving a file remove canjs `guide` map briefly #67

Open mikemitchel opened 4 years ago

mikemitchel commented 4 years ago

During a save of the legacy global window.gGuide file, there is a custom listener that update the appState level guide map for canjs. That listener actually replaces the map, which causes any stache files that do something like {{#if(this.guide)}} to re-render. Up until now, that has not cause an issue for the end user, but it is the root cause of the Mapper to go blank on auto-cleanup as per this issue: https://github.com/CCALI/a2jauthor/issues/59.

The long term fix is to change the canjs guide update to not replace the whole guide, but just update the property values. This code update will do it, but needs solid QA testing to make sure the global gGuide and canjs guide map stay in sync.

  // when window.gGuide is saved to the server successfully,
  // sync the map reference in the appState.
  $authorApp.on('author:guide-updated', function () {
    // this is work around for binding error in can-map
    const gGuideMapData = {}
    Object.keys(window.gGuide).forEach((key) => {
      gGuideMapData[key] = window.gGuide[key]
    })
    // update current CanMap with global gGuide state
    // 2nd param `true` removes props not in gGuideMapData from appState.guide
    appState.attr('guide').attr(gGuideMapData, true)
  })

the above replaces these code lines: https://github.com/CCALI/a2jauthor/blob/9a1bd3ab09680ec0c58f0aa043b383590e49df56/src/utils/bind-custom-events.js#L71-L81