Skip to content

Instantly share code, notes, and snippets.



Last active Sep 27, 2019
What would you like to do?
Dcerialize Trackable Entities Class template
{{> imports}}
export class {{class}} extends TrackableEntity {
{{{> properties}}}
{{{> constructor}}}
{{spaces 2}}constructor() {
{{spaces 4}}super();
{{spaces 4}}return super.proxify(this);
{{spaces 1}} }
{{spaces 2}}static onSerialized(json: IJsonObject, instance: {{class}}) {
{{spaces 4}}// Add ITrackable properties that cannot be decorated
{{spaces 4}}json["trackingState"] = instance.trackingState;
{{spaces 4}}json["modifiedProperties"] = SerializeSet<String>
{{spaces 4}}(
{{spaces 6}}Array.from(instance.modifiedProperties.values()),
{{spaces 6}}() => String
{{spaces 4}});
{{spaces 4}}// Custom processing of dates (May be empty)
{{#each properties}}
{{#ifCond property-type '==' 'Date'}}
{{spaces 4}}if (instance.{{property-name}}) {
{{spaces 6}}json["{{property-name}}"] = instance.{{property-name}}.toISOString();
{{spaces 4}} }
{{spaces 2}} }
import { TrackableEntity } from 'trackable-entities';
{{#each imports}}
import { {{import}} } from './{{import}}';
import {
} from "dcerialize";
{{#each properties}}
{{#ifCond property-type '==' 'number'}}
{{spaces 2}}@autoserializeAs(() => Number)
{{#ifCond property-type '==' 'string'}}
{{spaces 2}}@autoserializeAs(() => String)
{{#ifCond property-type '==' 'boolean'}}
{{spaces 2}}@autoserializeAs(() => Boolean)
{{#ifCond property-type '==' 'Date'}}
{{spaces 2}}@autoserializeAs(() => Date)
{{#ifCond property-type '==' 'any'}}
{{spaces 2}}@autoserializeAs(() => String)
{{spaces 2}}{{property-name}}: {{#ifCond property-type '==' 'any'}}string{{else}}{{property-type}}{{/ifCond}};
{{#if nav-properties}}
{{#each nav-properties}}
{{#if nav-property-collection}}
{{spaces 2}}@autoserializeAsArray(() => {{nav-property-type}})
{{spaces 2}}{{nav-property-name}}: {{nav-property-type}}[];
{{spaces 2}}@autoserializeAs(() => {{nav-property-type}})
{{spaces 2}}{{nav-property-name}}: {{nav-property-type}};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.