-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use async observer when target app is Ember 3.13+ (#777)
* Add `observer` util to opt in to async in 3.13+ * Remove code that skips column-reordering tests for 3.13+ * Use ember 3.12 in package.json * Fix lint * change eslint no-restricted-imports messages, pr feedback * Rename imported ember observer functions, pr feedback * Fix argument order for addObserver/removeObserver * Use `settled` to fix collapse-tree tests The use of `await settled()` seems to be required to properly wait for the now-async observers to finish notifying of property changes to the collapse tree. Also: * Fix propogate typo * Replace some hardcoded for loop lengths in tests with eg `expectedValue.length`
- Loading branch information
Showing
14 changed files
with
171 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { gte } from 'ember-compatibility-helpers'; | ||
import { assert } from '@ember/debug'; | ||
|
||
// eslint-disable-next-line no-restricted-imports | ||
import { observer as emberObserver } from '@ember/object'; | ||
|
||
// eslint-disable-next-line no-restricted-imports | ||
import { | ||
addObserver as emberAddObserver, | ||
removeObserver as emberRemoveObserver, | ||
} from '@ember/object/observers'; | ||
|
||
const USE_ASYNC_OBSERVERS = gte('3.13.0'); | ||
|
||
function asyncObserver(...args) { | ||
let fn = args.pop(); | ||
let dependentKeys = args; | ||
let sync = false; | ||
|
||
return emberObserver({ dependentKeys, fn, sync }); | ||
} | ||
|
||
function asyncAddObserver(...args) { | ||
let obj, path, target, method; | ||
let sync = false; | ||
obj = args[0]; | ||
path = args[1]; | ||
assert( | ||
`Expected 3 or 4 args for addObserver, got ${args.length}`, | ||
args.length === 3 || args.length === 4 | ||
); | ||
if (args.length === 3) { | ||
target = null; | ||
method = args[2]; | ||
} else if (args.length === 4) { | ||
target = args[2]; | ||
method = args[3]; | ||
} | ||
|
||
return emberAddObserver(obj, path, target, method, sync); | ||
} | ||
|
||
function asyncRemoveObserver(...args) { | ||
let obj, path, target, method; | ||
let sync = false; | ||
obj = args[0]; | ||
path = args[1]; | ||
assert( | ||
`Expected 3 or 4 args for addObserver, got ${args.length}`, | ||
args.length === 3 || args.length === 4 | ||
); | ||
if (args.length === 3) { | ||
target = null; | ||
method = args[2]; | ||
} else { | ||
target = args[2]; | ||
method = args[3]; | ||
} | ||
return emberRemoveObserver(obj, path, target, method, sync); | ||
} | ||
|
||
export const observer = USE_ASYNC_OBSERVERS ? asyncObserver : emberObserver; | ||
export const addObserver = USE_ASYNC_OBSERVERS ? asyncAddObserver : emberAddObserver; | ||
export const removeObserver = emberRemoveObserver ? asyncRemoveObserver : emberRemoveObserver; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.