@@ -106,24 +106,26 @@ export function observe(targets: string|string[]) {
106
106
}
107
107
108
108
/**
109
- * A TypeScript accessor decorator factory that causes the decorated accessor to
110
- * be called when a property changes. `targets` is either a single property
111
- * name, or a list of property names.
109
+ * A TypeScript accessor decorator factory that causes the decorated getter to
110
+ * be called when a set of dependencies change. The arguments of this decorator
111
+ * should be paths of the data dependencies as described
112
+ * [here](https://www.polymer-project.org/2.0/docs/devguide/observers#define-a-computed-property)
113
+ * The decorated getter should not have an associated setter.
112
114
*
113
115
* This function must be invoked to return a decorator.
114
116
*/
115
117
export function computed < T = any > ( ...targets : ( keyof T ) [ ] ) {
116
118
return ( proto : any , propName : string , descriptor : PropertyDescriptor ) : void => {
117
- const targetString = targets . join ( ',' ) ;
118
- const propNameCased = propName [ 0 ] . toUpperCase ( ) + propName . slice ( 1 ) ;
119
- const fnName = `__compute${ propNameCased } ` ;
119
+ const fnName = `__compute${ propName } ` ;
120
120
121
- proto . constructor . prototype [ fnName ] = descriptor . get ;
121
+ Object . defineProperty ( proto . constructor . prototype , fnName , {
122
+ get : descriptor . get
123
+ } ) ;
122
124
123
125
descriptor . get = undefined ;
124
126
125
127
createProperty ( proto , propName , {
126
- computed : `${ fnName } (${ targetString } )`
128
+ computed : `${ fnName } (${ targets . join ( ',' ) } )`
127
129
} ) ;
128
130
} ;
129
131
}
0 commit comments