Skip to content

Commit deefeb5

Browse files
authored
Move geteventlisteners to be imported from renderer (#54)
AOT tree-shook imports in the module
1 parent 4eb59f5 commit deefeb5

File tree

4 files changed

+28
-17
lines changed

4 files changed

+28
-17
lines changed

libs/core/src/lib/angular-react-browser.module.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import { NgModule } from '@angular/core';
55
import { BrowserModule, ɵDomRendererFactory2 } from '@angular/platform-browser';
6-
import './external/geteventlisteners';
76
import { AngularReactRendererFactory } from './renderer/renderer';
87

98
@NgModule({

libs/core/src/lib/external/geteventlisteners.ts renamed to libs/core/src/lib/renderer/geteventlisteners.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
// Taken and modified from https://github.com/colxi/getEventListeners to be compiled into ES5, allowing running in older browsers
22

3-
(function() {
4-
'use strict';
5-
3+
/**
4+
* Monkey-patches `Element`'s `addEventListener` & `removeEventListener` and adds `getEventListeners`.
5+
* This later allows the renderer to emit any event handlers attached to React-wrapped components as Angular Outputs:
6+
```html
7+
<my-component (arbitraryEvent)="onEventHandler($event)"></my-component>
8+
```
9+
*/
10+
export function initHooks() {
611
// save the original methods before overwriting them
712
Element.prototype['_addEventListener'] = Element.prototype.addEventListener;
813
Element.prototype['_removeEventListener'] = Element.prototype.removeEventListener;
@@ -83,4 +88,4 @@
8388
}
8489
};
8590
*/
86-
})();
91+
}

libs/core/src/lib/renderer/renderer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Disguise } from './components/Disguise';
88
import { ReactContent } from './react-content';
99
import { isReactNode, ReactNode } from './react-node';
1010
import { registerElement } from './registry';
11+
import { initHooks as initGetEventListeners } from './geteventlisteners';
1112

1213
const DEBUG = false;
1314

@@ -83,6 +84,9 @@ export class ReactRenderer implements Renderer2 {
8384
};
8485

8586
constructor(public readonly rootRenderer: AngularReactRendererFactory) {
87+
// Attach hooks to event handlers so we can intercept and re-emit any event handlers passed to React-wrapper components
88+
initGetEventListeners();
89+
8690
// These two elements are essential for the whole experience to be smooth for the user - register them from the get-go.
8791
registerElement('ReactContent', () => ReactContent);
8892
registerElement('Disguise', () => Disguise);

libs/fabric/package.json

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,34 @@
1111
"@angular-react/core": "ɵa",
1212
"office-ui-fabric-react/lib/Breadcrumb": "Breadcrumb",
1313
"office-ui-fabric-react/lib/Button": "Button",
14-
"office-ui-fabric-react/lib/Image": "Image",
15-
"office-ui-fabric-react/lib/Icon": "Icon",
16-
"office-ui-fabric-react/lib/Dialog": "Dialog",
17-
"office-ui-fabric-react/lib/Fabric": "Fabric",
14+
"office-ui-fabric-react/lib/Calendar": "Calendar",
1815
"office-ui-fabric-react/lib/Callout": "Callout",
1916
"office-ui-fabric-react/lib/Checkbox": "Checkbox",
2017
"office-ui-fabric-react/lib/ChoiceGroup": "ChoiceGroup",
2118
"office-ui-fabric-react/lib/ComboBox": "ComboBox",
2219
"office-ui-fabric-react/lib/CommandBar": "CommandBar",
2320
"office-ui-fabric-react/lib/DatePicker": "DatePicker",
21+
"office-ui-fabric-react/lib/DetailsList": "DetailsList",
22+
"office-ui-fabric-react/lib/Dialog": "Dialog",
2423
"office-ui-fabric-react/lib/Divider": "Divider",
24+
"office-ui-fabric-react/lib/Fabric": "Fabric",
2525
"office-ui-fabric-react/lib/GroupedList": "GroupedList",
26+
"office-ui-fabric-react/lib/HoverCard": "HoverCard",
27+
"office-ui-fabric-react/lib/Icon": "Icon",
28+
"office-ui-fabric-react/lib/Image": "Image",
29+
"office-ui-fabric-react/lib/Link": "Link",
30+
"office-ui-fabric-react/lib/MarqueeSelection": "MarqueeSelection",
31+
"office-ui-fabric-react/lib/MessageBar": "MessageBar",
32+
"office-ui-fabric-react/lib/Modal": "Modal",
2633
"office-ui-fabric-react/lib/Panel": "Panel",
2734
"office-ui-fabric-react/lib/Persona": "Persona",
28-
"office-ui-fabric-react/lib/Spinner": "Spinner",
29-
"office-ui-fabric-react/lib/MessageBar": "MessageBar",
30-
"office-ui-fabric-react/lib/Link": "Link",
3135
"office-ui-fabric-react/lib/Pivot": "Pivot",
32-
"office-ui-fabric-react/lib/Toggle": "Toggle",
33-
"office-ui-fabric-react/lib/HoverCard": "HoverCard",
34-
"office-ui-fabric-react/lib/Tooltip": "Tooltip",
35-
"office-ui-fabric-react/lib/Modal": "Modal",
36+
"office-ui-fabric-react/lib/SearchBox": "SearchBox",
3637
"office-ui-fabric-react/lib/Shimmer": "Shimmer",
3738
"office-ui-fabric-react/lib/Slider": "Slider",
38-
"office-ui-fabric-react/lib/SearchBox": "SearchBox"
39+
"office-ui-fabric-react/lib/Spinner": "Spinner",
40+
"office-ui-fabric-react/lib/Toggle": "Toggle",
41+
"office-ui-fabric-react/lib/Tooltip": "Tooltip"
3942
},
4043
"comments": "none"
4144
},

0 commit comments

Comments
 (0)