<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Correctly Extend a Class: Constructor in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/correctly-extend-a-class-constructor/m-p/1101478#M74766</link>
    <description>&lt;P&gt;I would probably do it like this.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;class SegmentGraphic extends Graphic {
  // so that all props are not required
  constructor(params: Partial&amp;lt;SegmentGraphic&amp;gt;) {}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 23 Sep 2021 21:43:53 GMT</pubDate>
    <dc:creator>ReneRubalcava</dc:creator>
    <dc:date>2021-09-23T21:43:53Z</dc:date>
    <item>
      <title>Correctly Extend a Class: Constructor</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/correctly-extend-a-class-constructor/m-p/1101464#M74764</link>
      <description>&lt;P&gt;I'm looking for guidance with how to properly extend a class with respect to its constructor. All of this is in typescript. I'm extending the Graphic class. Normally the graphics class take a&amp;nbsp;&lt;SPAN&gt;GraphicProperties object. I'm my class I had new properties.&amp;nbsp; I would like to change the constructor from&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;constructor(properties?: any) { ... }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;to&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;    constructor(properties?: SegmentProperties) { ... }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Also, is it possible to define the type of properties without initializing them in the constructor?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;My full code is below:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import Graphic from "@arcgis/core/Graphic";
import Polyline from "@arcgis/core/geometry/Polyline";
import LineSymbol3D from "@arcgis/core/symbols/LineSymbol3D";
import LineSymbol3DLayer from "@arcgis/core/symbols/LineSymbol3DLayer";

import { subclass, property } from "@arcgis/core/core/accessorSupport/decorators";
import GraphicsLayer from "@arcgis/core/layers/GraphicsLayer";
import Point from "@arcgis/core/geometry/Point";

import * as watchUtils from "@arcgis/core/core/watchUtils";

@subclass("esri.core.Graphic.SegmentGraphic")
export class SegmentGraphic extends Graphic{

    @property()
    startPoint: Graphic;

    @property()
    endPoint: Graphic;

    @property({
        readOnly: true
      })
      get length(): number {
        return 10;
      }

    constructor(properties?: any) {
        
        super(properties);
        this.startPoint = properties.startPoint;
        this.endPoint = properties.endPoint;

        this.updatePolyline()

        this.symbol = new LineSymbol3D({
            symbolLayers: [
                new LineSymbol3DLayer({
                    size: 5,
                    material: {
                        color: "red"
                    }
                })
            ]
        });

        this.registerWatchUtil(this.startPoint);
        this.registerWatchUtil(this.endPoint);
    }

    private updatePolyline() {
        let polyline = new Polyline({spatialReference: this.startPoint.geometry.spatialReference});
            polyline.addPath([this.startPoint.geometry as Point, this.endPoint.geometry as Point]);
            this.geometry = polyline 
    }

    private registerWatchUtil(point: Graphic){
        watchUtils.when(point, "geometry", (geometry) =&amp;gt; {
            this.updatePolyline()
        })
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Sep 2021 21:16:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/correctly-extend-a-class-constructor/m-p/1101464#M74764</guid>
      <dc:creator>Alexandre-Notos</dc:creator>
      <dc:date>2021-09-23T21:16:07Z</dc:date>
    </item>
    <item>
      <title>Re: Correctly Extend a Class: Constructor</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/correctly-extend-a-class-constructor/m-p/1101478#M74766</link>
      <description>&lt;P&gt;I would probably do it like this.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;class SegmentGraphic extends Graphic {
  // so that all props are not required
  constructor(params: Partial&amp;lt;SegmentGraphic&amp;gt;) {}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Sep 2021 21:43:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/correctly-extend-a-class-constructor/m-p/1101478#M74766</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2021-09-23T21:43:53Z</dc:date>
    </item>
  </channel>
</rss>

