Skip to content

Commit

Permalink
Avoid change directly after loading.
Browse files Browse the repository at this point in the history
Setting the _selected field on a model causes a navModel update, which in turn
causes head to change because of serialisation differences. To avoid this, we
don't call setNavModel if only _selected has been changed.

One other small change to avoid doNotReparse from leaking out.
  • Loading branch information
izak committed Mar 5, 2014
1 parent 3a5e1cc commit 0122e51
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions scripts/gh-book/opf-file.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ define [
# when we are internally updating models.
setNavModel = (options) =>
if not options.doNotReparse
options.doNotReparse = true
options = $.extend({doNotReparse: true}, options)

This comment has been minimized.

Copy link
@izak

izak Mar 5, 2014

Author

Because options is passed by reference, setting doNotReparse on it travels back up the calling chain and could potentially cause unexpected results. It does not appear to make any difference at the moment though, I just think this is more correct.

@navModel.set 'head', @_serializeNavModelHead(), options
@navModel.set 'body', @_serializeNavModelBody(), options

Expand Down Expand Up @@ -273,8 +273,9 @@ define [
@getChildren().on 'add remove tree:change tree:add tree:remove', (model, collection, options) =>
setNavModel(options)
@getChildren().on 'change reset', (collection, options) =>
# HACK: `?` is because `inherits/container.add` calls `trigger('change')`
setNavModel(options)
model = collection.dereferencePointer?() or collection
if not _.isEmpty _.omit model.changedAttributes?(), ['_selected']
setNavModel(options)

@manifest.on 'add', (model, collection, options) => @_addItem(model, options)

Expand Down

0 comments on commit 0122e51

Please sign in to comment.