Skip to content
Snippets Groups Projects
Select Git revision
  • 86cef5125a2ccd5920153d503dc046fee0b4fed7
  • main default protected
  • add_export_route
  • add_route_assignments
  • add_route_user
  • 4.1.0-dev
  • Pre-alpha
  • 4.0.1
  • Latest
  • 4.0.0
  • 3.5.0
  • 3.4.2
  • 3.4.1
  • 3.3.0
  • 3.2.3
  • 3.2.2
  • 3.2.0
  • 3.1.2
  • 3.1.1
  • 3.1.0
  • 3.0.1
  • 3.0.0
  • 2.2.0
  • 2.1.0
  • 2.0.0
25 results

Model.ts

Blame
  • Forked from Dojo Project (HES-SO) / Projects / UI / DojoCLI
    Source project has a limited visibility.
    Model.ts 524 B
    type Constructor<T> = new (...args: any[]) => T;
    
    
    abstract class Model extends Object {
        static createFromJson<T extends Object>(this: Constructor<T>, obj: any): T {
            const result = new this();
    
            Object.getOwnPropertyNames(obj).forEach(property => {
                if ( result.hasOwnProperty(property) ) {
    
                    (result as any)[property] = property.indexOf('Info') === -1 ? obj[property] : JSON.parse(obj[property]);
                }
            });
            return result;
        }
    }
    
    
    export default Model;