-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kelly Selden
committed
Jul 9, 2016
1 parent
f335be0
commit 8097f4d
Showing
2 changed files
with
71 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import Ember from 'ember'; | ||
import computed from 'ember-computed-decorators'; | ||
|
||
const { | ||
Service, | ||
computed: { not, or }, | ||
get, setProperties, | ||
merge | ||
} = Ember; | ||
|
||
export default Service.extend({ | ||
setupComputeds(dependency, shouldSetupVersions = true) { | ||
let props = { | ||
@computed('firstVersion', 'secondVersion') | ||
areVersionsDifferent(firstVersion, secondVersion) { | ||
if (!firstVersion || !secondVersion) { | ||
return false; | ||
} | ||
|
||
return firstVersion !== secondVersion; | ||
}, | ||
|
||
@computed('isSomethingWrong', 'dependencies.@each.numberOfDifferences') | ||
numberOfDifferences(isSomethingWrong, dependencies) { | ||
let initialValue = isSomethingWrong ? 1 : 0; | ||
|
||
if (get(dependencies, 'promise') && !get(dependencies, 'isFulfilled')) { | ||
return initialValue; | ||
} | ||
|
||
let numberOfDifferences = dependencies.reduce((previousValue, currentValue) => { | ||
return previousValue + get(currentValue, 'numberOfDifferences'); | ||
}, initialValue); | ||
|
||
return numberOfDifferences; | ||
}, | ||
|
||
@computed('dependencies.@each.isDoneCrawling') | ||
isDoneCrawling(dependencies) { | ||
if (get(dependencies, 'promise') && !get(dependencies, 'isFulfilled')) { | ||
return false; | ||
} | ||
|
||
let areChildrenDoneCrawling = !dependencies.filterBy('isDoneCrawling', false).length; | ||
let stopCrawling = get(this, 'stopCrawling'); | ||
|
||
return areChildrenDoneCrawling && !stopCrawling; | ||
} | ||
}; | ||
|
||
if (shouldSetupVersions) { | ||
merge(props, { | ||
isFirstVersionHintMissing: not('firstVersionHint'), | ||
isSecondVersionHintMissing: not('secondVersionHint'), | ||
isOneHintMissing: or('isFirstVersionHintMissing', 'isSecondVersionHintMissing'), | ||
isSomethingWrong: or('isOneMissing', 'areVersionsDifferent') | ||
}); | ||
} | ||
|
||
setProperties(dependency, props); | ||
} | ||
}); |