|
2 | 2 | * React Component Base |
3 | 3 | */ |
4 | 4 | import * as React from 'react'; |
| 5 | + import * as ReactDOM from 'react-dom'; |
5 | 6 | import { extend, isNullOrUndefined, setValue, getValue, isObject } from '@syncfusion/ej2-base'; |
6 | 7 | /** |
7 | 8 | * Interface for processing directives |
|
47 | 48 | public static reactUid: number = 1; |
48 | 49 | private setProperties: Function; |
49 | 50 | private element: any; |
| 51 | + private mountingState:any = false; |
50 | 52 | private appendTo: Function; |
51 | 53 | private destroy: Function; |
52 | 54 | private getModuleName: () => string; |
|
68 | 70 | private isshouldComponentUpdateCalled: boolean = false; |
69 | 71 | private modelObserver: any; |
70 | 72 | private isDestroyed: boolean; |
| 73 | + private isCreated: boolean = false; |
71 | 74 | private isProtectedOnChange: boolean; |
72 | 75 | private canDelayUpdate: boolean; |
73 | 76 | private reactElement: HTMLElement; |
|
88 | 91 | // tslint:disable-next-line:no-any |
89 | 92 | this.renderReactComponent(); |
90 | 93 | if (this.portals && this.portals.length) { |
| 94 | + this.mountingState = true; |
91 | 95 | this.renderReactTemplates(); |
| 96 | + this.mountingState = false; |
92 | 97 | } |
93 | 98 | } |
94 | 99 |
|
|
103 | 108 |
|
104 | 109 | private renderReactComponent(): void { |
105 | 110 | let ele: Element = this.reactElement; |
106 | | - if (ele) { |
| 111 | + if (ele && !this.isAppendCalled) { |
107 | 112 | this.isAppendCalled = true; |
108 | 113 | this.appendTo(ele); |
109 | 114 | } |
|
280 | 285 | this.isProtectedOnChange = false; |
281 | 286 | if(eventName === 'created') { |
282 | 287 | setTimeout(()=>{ |
| 288 | + this.isCreated = true; |
283 | 289 | if(!this.isDestroyed) { |
284 | 290 | this.modelObserver.notify(eventName, eventProp, successHandler); |
285 | 291 | } |
|
450 | 456 | clearTimeout(this.cachedTimeOut); |
451 | 457 | var modulesName = ['dropdowntree', 'checkbox']; |
452 | 458 | // tslint:disable-next-line:no-any |
453 | | - if (this.initRenderCalled && this.isAppendCalled && this.element && (!modulesName.indexOf(this.getModuleName())) ? document.body.contains(this.element) : true && !this.isDestroyed) { |
| 459 | + if (this.initRenderCalled && this.isAppendCalled && this.element && ((!modulesName.indexOf(this.getModuleName())) ? document.body.contains(this.element) : true) && !this.isDestroyed && this.isCreated) { |
454 | 460 | this.destroy(); |
455 | 461 | } |
456 | 462 |
|
457 | 463 | } |
458 | | - // tslint:disable:no-any |
| 464 | + |
| 465 | + // tslint:disable:no-any |
| 466 | + public appendReactElement (element: any, container: HTMLElement) { |
| 467 | + let portal: any = (ReactDOM as any).createPortal(element, container); |
| 468 | + if (!this.portals) { |
| 469 | + this.portals = [portal]; |
| 470 | + } |
| 471 | + else { |
| 472 | + this.portals.push(portal); |
| 473 | + } |
| 474 | + }; |
| 475 | + // tslint:disable:no-any |
| 476 | + public intForceUpdate (callback?: any): void { |
| 477 | + let flush: any = getValue('flushSync',ReactDOM); |
| 478 | + if (this.initRenderCalled && flush && !this.mountingState) { |
| 479 | + flush(() => { |
| 480 | + this.forceUpdate(callback); |
| 481 | + }); |
| 482 | + } else { |
| 483 | + this.forceUpdate(callback); |
| 484 | + } |
| 485 | + } |
| 486 | + |
459 | 487 | public renderReactTemplates (callback?: any): void { |
460 | 488 | this.isReactForeceUpdate = true; |
461 | | - if(callback){ |
462 | | - this.forceUpdate(callback); |
463 | | - } else { |
464 | | - this.forceUpdate(); |
465 | | - } |
466 | | - |
| 489 | + this.intForceUpdate(callback); |
467 | 490 | this.isReactForeceUpdate = false; |
468 | 491 | }; |
469 | 492 | // tslint:disable:no-any |
|
0 commit comments