Skip to content

Commit

Permalink
feat(observable): add propertyName argument
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertHerhold authored and jdanyow committed Sep 2, 2016
1 parent 044746f commit e7825eb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/decorator-observable.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function observable(targetOrConfig: any, key: string, descriptor?: Proper
let oldValue = this[innerPropertyName];
this[innerPropertyName] = newValue;
if (this[callbackName]) {
this[callbackName](newValue, oldValue);
this[callbackName](newValue, oldValue, key);
}
};

Expand Down
14 changes: 7 additions & 7 deletions test/decorator-observable.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('observable decorator', () => {
spyOn(instance, 'valueChanged');

instance.value = newValue;
expect(instance.valueChanged).toHaveBeenCalledWith(newValue, oldValue);
expect(instance.valueChanged).toHaveBeenCalledWith(newValue, oldValue, 'value');
});

it('should call valueChanged when changing the undefined property', () => {
Expand All @@ -25,7 +25,7 @@ describe('observable decorator', () => {
spyOn(instance, 'valueChanged');

instance.value = newValue;
expect(instance.valueChanged).toHaveBeenCalledWith(newValue, undefined);
expect(instance.valueChanged).toHaveBeenCalledWith(newValue, undefined, 'value');
});

it('should call customHandler when changing the property', () => {
Expand All @@ -36,7 +36,7 @@ describe('observable decorator', () => {
spyOn(instance, 'customHandler');

instance.value = newValue;
expect(instance.customHandler).toHaveBeenCalledWith(newValue, oldValue);
expect(instance.customHandler).toHaveBeenCalledWith(newValue, oldValue, 'value');
});

it('should call customHandler when changing the undefined property', () => {
Expand All @@ -47,7 +47,7 @@ describe('observable decorator', () => {
spyOn(instance, 'customHandler');

instance.value = newValue;
expect(instance.customHandler).toHaveBeenCalledWith(newValue, undefined);
expect(instance.customHandler).toHaveBeenCalledWith(newValue, undefined, 'value');
});

it('should work when valueChanged is undefined', () => {
Expand Down Expand Up @@ -81,7 +81,7 @@ describe('observable decorator', () => {
spyOn(instance, 'valueChanged');

instance.value = newValue;
expect(instance.valueChanged).toHaveBeenCalledWith(newValue, oldValue);
expect(instance.valueChanged).toHaveBeenCalledWith(newValue, oldValue, 'value');
});

it('should work with decorators function when property is undefined', () => {
Expand All @@ -92,7 +92,7 @@ describe('observable decorator', () => {
spyOn(instance, 'valueChanged');

instance.value = newValue;
expect(instance.valueChanged).toHaveBeenCalledWith(newValue, undefined);
expect(instance.valueChanged).toHaveBeenCalledWith(newValue, undefined, 'value');
});

it('should work with decorators function and config', () => {
Expand All @@ -106,6 +106,6 @@ describe('observable decorator', () => {
spyOn(instance, 'customHandler');

instance.value = newValue;
expect(instance.customHandler).toHaveBeenCalledWith(newValue, oldValue);
expect(instance.customHandler).toHaveBeenCalledWith(newValue, oldValue, 'value');
});
});

0 comments on commit e7825eb

Please sign in to comment.