-
-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #170 from offirgolan/underscore-super
Only call super on validations class if it exists via shouldCallSuper
- Loading branch information
Showing
5 changed files
with
162 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Copyright 2016, Yahoo! Inc. | ||
* Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms. | ||
*/ | ||
|
||
/** | ||
* Checks if the give key exists on the object's super. | ||
* If so, we can successfuly call the obj[key] _super | ||
* | ||
* Created by @rwjblue | ||
*/ | ||
export default function shouldCallSuper(obj, key) { | ||
let current = Object.getPrototypeOf(obj); | ||
current = Object.getPrototypeOf(current); | ||
|
||
while (current) { | ||
let descriptor = Object.getOwnPropertyDescriptor(current, key); | ||
|
||
if (descriptor) { | ||
return true; | ||
} | ||
|
||
current = Object.getPrototypeOf(current); | ||
} | ||
|
||
return false; | ||
} |
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 |
---|---|---|
@@ -1,3 +1,8 @@ | ||
/** | ||
* Copyright 2016, Yahoo! Inc. | ||
* Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms. | ||
*/ | ||
|
||
export function hasEmberData() { | ||
return typeof self.DS !== 'undefined'; | ||
} |
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,37 @@ | ||
import Ember from 'ember'; | ||
import { module, test } from 'qunit'; | ||
import shouldCallSuper from 'ember-cp-validations/utils/should-call-super'; | ||
|
||
const { | ||
computed | ||
} = Ember; | ||
|
||
module('Unit | Utils | shouldCallSuper'); | ||
|
||
test('shouldCallSuper - true', function(assert) { | ||
const Parent = Ember.Object.extend({ | ||
foo: computed(function() {}) | ||
}); | ||
|
||
const Child = Parent.extend({ | ||
foo: computed(function() { | ||
assert.ok(shouldCallSuper(this, 'foo')); | ||
}) | ||
}); | ||
|
||
const child = Child.create(); | ||
child.get('foo'); | ||
}); | ||
|
||
test('shouldCallSuper - false', function(assert) { | ||
const Parent = Ember.Object.extend(); | ||
|
||
const Child = Parent.extend({ | ||
foo: computed(function() { | ||
assert.ok(!shouldCallSuper(this, 'foo')); | ||
}) | ||
}); | ||
|
||
const child = Child.create(); | ||
child.get('foo'); | ||
}); |