Skip to content

Commit 5b4df68

Browse files
authored
Merge pull request #25 from Microsoft/misc-cleanup
Misc cleanup
2 parents 0561e92 + 2a8b048 commit 5b4df68

File tree

11 files changed

+155
-135
lines changed

11 files changed

+155
-135
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,11 @@ export abstract class ReactWrapperComponent<TProps extends {}> implements AfterV
9494
/**
9595
* Creates an instance of ReactWrapperComponent.
9696
* @param elementRef The host element.
97-
* @param setHostDisplay Whether the host's `display` should be set to the root child node's `display`. defaults to `false`
97+
* @param changeDetectorRef The change detector for the component.
98+
* @param renderer The Angular renderer.
9899
*/
99100
constructor(
100-
public readonly elementRef: ElementRef,
101+
public readonly elementRef: ElementRef<HTMLElement>,
101102
private readonly changeDetectorRef: ChangeDetectorRef,
102103
private readonly renderer: Renderer2,
103104
private readonly setHostDisplay: boolean = false
@@ -127,13 +128,14 @@ export abstract class ReactWrapperComponent<TProps extends {}> implements AfterV
127128
ngOnChanges(changes: SimpleChanges) {
128129
this._passAttributesAsProps();
129130

130-
this.detectChanges();
131+
this.markForCheck();
131132
}
132133

133134
/**
134-
* Trigger change detection on the component.
135+
* Mark the component as one that needed re-rendering on the React side,
136+
* and mark for change detection on the Angular side.
135137
*/
136-
protected detectChanges() {
138+
protected markForCheck() {
137139
if (isReactNode(this.reactNodeRef.nativeElement)) {
138140
this.reactNodeRef.nativeElement.setRenderPending();
139141
}
File renamed without changes.

libs/core/src/lib/declarations/public-api.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
export * from './index-signature';
55
export * from './known-keys';
66
export * from './omit';
7-
export * from './StringMap';
7+
export * from './string-map';
File renamed without changes.

libs/core/src/lib/renderer/react-content.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import * as React from 'react';
55
import * as ReactDOM from 'react-dom';
6-
import { Omit } from '../declarations/omit';
76
import * as dom from '../utils/dom';
87

98
const DEBUG = false;
@@ -12,14 +11,7 @@ export const CHILDREN_TO_APPEND_PROP = 'children-to-append';
1211
/**
1312
* Props that can be passed to `ReactContent` from users.
1413
*/
15-
export type ReactContentProps = Omit<AllReactContentProps, typeof CHILDREN_TO_APPEND_PROP>;
16-
17-
/**
18-
* @internal
19-
*/
20-
export interface AllReactContentProps {
21-
readonly [CHILDREN_TO_APPEND_PROP]: HTMLElement[];
22-
14+
export interface ReactContentProps {
2315
/**
2416
* Experimental rendering mode.
2517
* Uses a similar approach to `router-outlet`, where the child elements are added to the parent, instead of this node, and this is hidden.
@@ -28,14 +20,34 @@ export interface AllReactContentProps {
2820
legacyRenderMode?: boolean;
2921
}
3022

23+
/**
24+
* Creates a new `ReactContent` element.
25+
* @param children The children to append to the `ReactContent` element.
26+
* @param additionalProps _Optional_. @see `ReactContentProps`
27+
* @returns
28+
*/
29+
export function createReactContentElement(children: ReadonlyArray<HTMLElement>, additionalProps?: ReactContentProps) {
30+
return React.createElement(ReactContent, {
31+
...additionalProps,
32+
[CHILDREN_TO_APPEND_PROP]: children,
33+
});
34+
}
35+
36+
/**
37+
* @internal
38+
*/
39+
export interface InternalReactContentProps extends ReactContentProps {
40+
readonly [CHILDREN_TO_APPEND_PROP]: ReadonlyArray<HTMLElement>;
41+
}
42+
3143
/**
3244
* Render any `HTMLElement`s (including Angular components) as a child of React components.
3345
* Supports two rendering modes:
3446
* 1. `legacy` - append `<react-content>` as the root, and nest the `children-to-append` underneath it.
3547
* 2. `new` (**default**) - append the `children-to-append` to the parent of this component, and hide the `<react-content>` element.
3648
* (similar to how `router-outlet` behaves in Angular).
3749
*/
38-
export class ReactContent extends React.PureComponent<AllReactContentProps> {
50+
export class ReactContent extends React.PureComponent<InternalReactContentProps> {
3951
componentDidMount() {
4052
const element = ReactDOM.findDOMNode(this);
4153
if (this.props[CHILDREN_TO_APPEND_PROP]) {

0 commit comments

Comments
 (0)