BREAKING CHANGE(Smartjson): Require TC39 Stage 3 decorators for @foldDec (use accessor), switch foldDec to initializer-based implementation, improve buffer encode/decode handling, bump dependencies and update docs/tests.
This commit is contained in:
21
ts/index.ts
21
ts/index.ts
@@ -207,14 +207,23 @@ export class Smartjson {
|
||||
}
|
||||
|
||||
/**
|
||||
* Decorator that marks a property as foldable
|
||||
* Decorator that marks a property as foldable (TC39 Stage 3 decorator)
|
||||
* Use with the `accessor` keyword: @foldDec() accessor myProp: string;
|
||||
*/
|
||||
export const foldDec = () => {
|
||||
return (target: any, key: string) => {
|
||||
if (!target.saveableProperties) {
|
||||
target.saveableProperties = [];
|
||||
}
|
||||
target.saveableProperties.push(key);
|
||||
return <This extends Smartjson, Value>(
|
||||
_value: ClassAccessorDecoratorTarget<This, Value>,
|
||||
context: ClassAccessorDecoratorContext<This, Value>
|
||||
): ClassAccessorDecoratorResult<This, Value> | void => {
|
||||
const propertyName = String(context.name);
|
||||
context.addInitializer(function (this: This) {
|
||||
if (!this.saveableProperties) {
|
||||
this.saveableProperties = [];
|
||||
}
|
||||
if (!this.saveableProperties.includes(propertyName)) {
|
||||
this.saveableProperties.push(propertyName);
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user