Skip to content

Commit 09848a4

Browse files
fix(common): Fix implementation of 'pick' -- use hasOwnProperty
Closes #53
1 parent 0b1e9ed commit 09848a4

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/common/common.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,9 @@ export function ancestors(first: StateObject, second: StateObject) {
234234

235235
/**
236236
* Return a copy of the object only containing the whitelisted properties.
237-
238-
* @example
239-
* ```
240237
*
238+
* #### Example:
239+
* ```
241240
* var foo = { a: 1, b: 2, c: 3 };
242241
* var ab = pick(foo, ['a', 'b']); // { a: 1, b: 2 }
243242
* ```
@@ -246,8 +245,7 @@ export function ancestors(first: StateObject, second: StateObject) {
246245
*/
247246
export function pick(obj: Obj, propNames: string[]): Obj {
248247
let copy = {};
249-
// propNames.forEach(prop => { if (obj.hasOwnProperty(prop)) copy[prop] = obj[prop] });
250-
propNames.forEach(prop => { if (isDefined(obj[prop])) copy[prop] = obj[prop] });
248+
propNames.forEach(prop => { if (obj.hasOwnProperty(prop)) copy[prop] = obj[prop] });
251249
return copy;
252250
}
253251

test/transitionSpec.ts

+15
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,21 @@ describe('transition', function () {
864864
done();
865865
});
866866

867+
it('should not inherit previous params when new params are passed', async(done) => {
868+
router.stateRegistry.register({
869+
name: 'foo',
870+
url: '?fooParam',
871+
});
872+
873+
await $state.go('foo', { fooParam: 'abc' });
874+
expect(router.globals.params).toEqualValues({ fooParam: 'abc' });
875+
876+
await $state.go('foo', { fooParam: undefined });
877+
expect(router.globals.params).toEqualValues({ fooParam: undefined });
878+
879+
done();
880+
});
881+
867882
it('should not inherit params whose type has inherit: false', async(done) => {
868883
router.urlService.config.type('inherit', {
869884
inherit: true, encode: x => x, decode: x => x, is: () => true, equals: equals, pattern: /.*/, raw: false,

0 commit comments

Comments
 (0)