Skip to content

Commit bd7eaaa

Browse files
authored
Revert "Allow wrapping any React component with an Angular one on-the-fly" (#111)
Reverts #106 Issues with AOT builds including this, reverting until resolved.
1 parent b756043 commit bd7eaaa

File tree

19 files changed

+31
-219
lines changed

19 files changed

+31
-219
lines changed

apps/demo/src/app/app.component.html

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ <h2>Getting up and running...</h2>
99
</ol>
1010
</div>
1111

12-
<h5>Generic React component wrapper</h5>
13-
<my-counter [count]="count" (onIncrement)="reactCustomOnIncrement($event)">
14-
<div style="text-transform: uppercase;color:red">test</div>
15-
</my-counter>
16-
1712
<fab-checkbox label="foo" [renderLabel]="renderCheckboxLabel"></fab-checkbox>
1813

1914
<div style="width:500px">

apps/demo/src/app/app.component.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,6 @@ export class AppComponent {
178178
this.onDecrement = this.onDecrement.bind(this);
179179
}
180180

181-
count = 3;
182-
183-
reactCustomOnIncrement(newCount: number) {
184-
this.count = newCount;
185-
}
186-
187181
customItemCount = 1;
188182

189183
// FIXME: Allow declarative syntax too

apps/demo/src/app/app.module.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AngularReactBrowserModule, wrapComponent } from '@angular-react/core';
1+
import { AngularReactBrowserModule } from '@angular-react/core';
22
import {
33
FabBreadcrumbModule,
44
FabButtonModule,
@@ -35,18 +35,11 @@ import {
3535
FabSpinButtonModule,
3636
FabTextFieldModule,
3737
} from '@angular-react/fabric';
38-
import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core';
38+
import { NgModule } from '@angular/core';
3939
import { NxModule } from '@nrwl/nx';
4040
import { initializeIcons } from 'office-ui-fabric-react/lib/Icons';
4141
import { AppComponent } from './app.component';
4242
import { CounterComponent } from './counter/counter.component';
43-
import { CounterProps, Counter } from './counter/react-counter';
44-
45-
const MyCounterComponent = wrapComponent<CounterProps>({
46-
ReactComponent: Counter,
47-
selector: 'my-counter',
48-
// propNames: ['count', 'onIncrement'], // needed if propTypes are not defined on `ReactComponent`
49-
});
5043

5144
@NgModule({
5245
imports: [
@@ -87,9 +80,8 @@ const MyCounterComponent = wrapComponent<CounterProps>({
8780
FabSpinButtonModule,
8881
FabTextFieldModule,
8982
],
90-
declarations: [AppComponent, CounterComponent, MyCounterComponent],
83+
declarations: [AppComponent, CounterComponent],
9184
bootstrap: [AppComponent],
92-
schemas: [NO_ERRORS_SCHEMA],
9385
})
9486
export class AppModule {
9587
constructor() {

apps/demo/src/app/counter/react-counter.tsx

Lines changed: 0 additions & 27 deletions
This file was deleted.

apps/demo/tsconfig.app.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
"extends": "../../tsconfig.json",
33
"compilerOptions": {
44
"outDir": "../../dist/out-tsc/apps/demo",
5-
"module": "es2015",
6-
"jsx": "react"
5+
"module": "es2015"
76
},
87
"include": ["**/*.ts"],
98
"exclude": ["**/*.spec.ts", "src/test.ts"]

libs/core/src/lib/components/generic-wrap-component.ts

Lines changed: 0 additions & 131 deletions
This file was deleted.

libs/core/src/lib/components/wrapper-component.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
Renderer2,
1313
SimpleChanges,
1414
AfterContentInit,
15-
ɵBaseDef,
1615
} from '@angular/core';
1716
import classnames from 'classnames';
1817
import toStyle from 'css-to-style';
@@ -22,10 +21,9 @@ import { Many } from '../declarations/many';
2221
import { ReactContentProps } from '../renderer/react-content';
2322
import { isReactNode } from '../renderer/react-node';
2423
import { isReactRendererData } from '../renderer/renderer';
25-
import { fromPairs } from '../utils/object/from-pairs';
24+
import { toObject } from '../utils/object/to-object';
2625
import { afterRenderFinished } from '../utils/render/render-delay';
2726
import { InputRendererOptions, JsxRenderFunc, createInputJsxRenderer, createRenderPropHandler } from './render-props';
28-
import { omit } from '../utils/object/omit';
2927

3028
// Forbidden attributes are still ignored, since they may be set from the wrapper components themselves (forbidden is only applied for users of the wrapper components)
3129
const ignoredAttributeMatchers = [/^_?ng-?.*/, /^style$/, /^class$/];
@@ -233,23 +231,17 @@ export abstract class ReactWrapperComponent<TProps extends {}> implements AfterC
233231
);
234232

235233
const eventListeners = this.elementRef.nativeElement.getEventListeners();
236-
// Event listeners already being handled natively by the derived component
237-
const handledEventListeners = Object.keys(
238-
((this.constructor as any).ngBaseDef as ɵBaseDef<any>).outputs
239-
) as (keyof typeof eventListeners)[];
240-
const unhandledEventListeners = omit(eventListeners, ...handledEventListeners);
241-
242234
const eventHandlersProps =
243-
unhandledEventListeners && Object.keys(unhandledEventListeners).length
244-
? fromPairs(
245-
Object.values(unhandledEventListeners).map<[string, React.EventHandler<React.SyntheticEvent>]>(
246-
([eventListener]) => [
247-
eventListener.type,
248-
(ev: React.SyntheticEvent) => eventListener.listener(ev && ev.nativeEvent),
249-
]
250-
)
235+
eventListeners && Object.keys(eventListeners).length
236+
? toObject(
237+
Object.values(eventListeners).map<[string, React.EventHandler<React.SyntheticEvent>]>(([eventListener]) => [
238+
eventListener.type,
239+
(ev: React.SyntheticEvent) => eventListener.listener(ev && ev.nativeEvent),
240+
])
251241
)
252242
: {};
243+
{
244+
}
253245

254246
this.reactNodeRef.nativeElement.setProperties({ ...props, ...eventHandlersProps });
255247
}

libs/core/src/lib/declarations/known-keys.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
2-
// Licensed under the MIT License.
3-
41
// prettier-ignore
52
/**
63
* Get the known keys (i.e. no index signature) of T.
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
2-
// Licensed under the MIT License.
3-
41
export type Many<T> = T | T[];

libs/core/src/lib/utils/object/from-pairs.ts renamed to libs/core/src/lib/utils/object/to-object.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Transforms an array of [key, value] tuples to an object
33
*/
4-
export function fromPairs<T extends [PropertyKey, any][]>(pairs: T): object {
4+
export function toObject<T extends [string, any][]>(pairs: T): object {
55
return pairs.reduce(
66
(acc, [key, value]) =>
77
Object.assign(acc, {

0 commit comments

Comments
 (0)