-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate Ember object types in resolver
This commit adds assertions to ensure that some key object types are validated when they are resolved: * Routes * Components * Views * Services I did not add a validation for controller classes because the implementation for detection would need to be a little different (can't simply use #detect). Also some of Ember's tests play fast (and loose) with with the types of things they try to pass off as controllers. For now I don't think this additional validation is worth adding given imminent demise of Controllers.
- Loading branch information
1 parent
37f4325
commit 67394f7
Showing
3 changed files
with
66 additions
and
0 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,24 @@ | ||
/** | ||
@module ember | ||
@submodule ember-application | ||
*/ | ||
|
||
import Route from "ember-routing/system/route"; | ||
import Component from "ember-views/views/component"; | ||
import View from "ember-views/views/view"; | ||
import Service from "ember-runtime/system/service"; | ||
|
||
let VALIDATED_TYPES = { | ||
route: Route, | ||
component: Component, | ||
view: View, | ||
service: Service | ||
}; | ||
|
||
export default function validateType(resolvedType, parsedName) { | ||
let expectedType = VALIDATED_TYPES[parsedName.type]; | ||
|
||
Ember.assert(`Expected ${parsedName.fullName} to resolve to an ${expectedType} but instead it was ${resolvedType}.`, function() { | ||
return !expectedType || expectedType.detect(resolvedType); | ||
}); | ||
} |
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