-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Fix shapes update #7424
Fix shapes update #7424
Changes from 3 commits
a62e2b1
52c1ca0
a17a802
89adb73
700609d
a301e8c
5d6cfe9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,7 +86,6 @@ define(function (require, exports, module) { | |
| } | ||
|
|
||
| /** | ||
| * @private | ||
| * Inject remote live editor driver and any specified editor providers. | ||
| * The remote live editor driver mirrors most of the local live editor driver API | ||
| * to provide an interface to the in-browser live editor. | ||
|
|
@@ -104,16 +103,16 @@ define(function (require, exports, module) { | |
| } | ||
|
|
||
| /** | ||
| * @private | ||
| * Send instructions to remove the live editor from the page in LivePreview. | ||
| * @return {$.Promise} | ||
| */ | ||
| function remove() { | ||
| if (_hasEditor === false) { | ||
| var deferred = $.Deferred(); | ||
| return deferred.reject(); | ||
| return deferred.reject().promise(); | ||
| } | ||
|
|
||
| _cache.model = undefined; // do not move in _reset(), otherwhise the _reconnect() scenario miss the cache and fail | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some typos. Should be
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One typo: otherwhise |
||
| _reset(); | ||
| var expr = _namespace + ".remove()"; | ||
| return _call(expr); | ||
|
|
@@ -138,6 +137,10 @@ define(function (require, exports, module) { | |
| hasChanged = false, | ||
| key; | ||
|
|
||
| if (!data) { | ||
| remove(); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @oslego We should also return |
||
|
|
||
| // sync the local model snapshot with the remote model | ||
| _.forEach(data, function (value, key) { | ||
| if (!_model[key] || !_.isEqual(_model[key], value)) { | ||
|
|
@@ -155,18 +158,26 @@ define(function (require, exports, module) { | |
| /** | ||
| * @private | ||
| * Handle failed promises for eval() calls to the inspected page. | ||
| * Promises can fail if the user manually refreshes the page or navigates | ||
| * Promises fail if the user manually refreshes the page or navigates | ||
| * because the injected editor files will be lost. | ||
| * If this is the case, attempt to reconnect. | ||
| * | ||
| * Promises also fail because of errors thrown in the remote page. | ||
| * If this is the case, remove the editor. | ||
| * | ||
| * @param {$.Promise=} result promise result | ||
| * @param {$.Deferred=} result | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like you are no longer using this parameter |
||
| */ | ||
| function _whenRemoteCallFailed(result) { | ||
| if (result) { | ||
| return _reconnect(); | ||
| } else { | ||
| _cache.model = undefined; | ||
| return remove(); | ||
| } | ||
| // check if the remote editor namespace is still defined on the page | ||
| _call(_namespace) | ||
| .then(function (response) { | ||
| if (response.type === "undefined") { | ||
| _reconnect(); | ||
| } else { | ||
| remove(); | ||
| } | ||
| }) | ||
| .fail(remove); | ||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You also need to return
return deferred.reject().promise()on line 73 inside_call()function.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It already returns
.reject()on line 73There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I updated it to
reject().promise()after I realized that I forgot to append the promise(). So it should have .promise().There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And actually this is from @TomMalbran in this comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On line 73 it returns
.reject()so it may be caught by_whenRemoteCallFailed()downstream.In that scenario (Inspector not connected), it will attempt reconnect a few times, then finally give up and remove the editor. Returning
.reject().promise()instead won't bypass this workflow?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this line it is just a minor nit, so that the returned objects are always the same and correspond to the JSDocs.
The idea of returning a Promise is so that the function that uses it can't call resolve or reject over the deferred object. But since you are already returning a rejected deferred, the state can't be changed so returning a promise won't change that. You can still use then, done, fail, an all those methods on a promise.