Skip to content

Commit 8416429

Browse files
author
Ben Grynhaus
committed
Merge branch 'next' into declarative-pattern# Conflicts:# libs/core/src/renderer/renderprop-helpers.ts
2 parents d0ea893 + 9a0db80 commit 8416429

File tree

8 files changed

+143
-137
lines changed

8 files changed

+143
-137
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"Packagr",
77
"Renderable",
88
"Selectable",
9+
"VDOM",
910
"borderless",
1011
"checkmark",
1112
"commandbar",

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ Switched to a new branch 'pr/999'
7373
To get latest changes to the PR:
7474

7575
```
76+
$ git checkout pr/1000
7677
$ git pull --tags origin refs/pull/1000/head
7778
From https://github.com/benfeely/angular-react
7879
* branch refs/pull/1000/head -> FETCH_HEAD

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ <h2>Getting up and running...</h2>
44

55
<ol>
66
<li>Add
7-
<i>AngularReactBrowserModule</i>> to
7+
<i>AngularReactBrowserModule</i> to
88
<i>app.module.ts</i> in place of the default
99
<i>BrowserModule</i>.</li>
1010
<li>Add

libs/core/package-lock.json

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

libs/core/src/renderer/react-node.ts

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as ReactDOM from 'react-dom';
55

66
import removeUndefinedProperties from '../utils/object/remove-undefined-properties';
77
import { CHILDREN_TO_APPEND_PROP } from './react-content';
8-
import { getComponentClass } from "./registry";
8+
import { getComponentClass } from './registry';
99

1010
const DEBUG = false;
1111

@@ -37,6 +37,10 @@ export class ReactNode {
3737
this.setRenderPending();
3838
}
3939

40+
get parent(): HTMLElement | ReactNode {
41+
return this._parent;
42+
}
43+
4044
private isNotRenderable: boolean;
4145
get shouldRender() {
4246
return !this.isNotRenderable;
@@ -80,13 +84,15 @@ export class ReactNode {
8084
// If type is still a string, then no React Element matches this string.
8185
this.typeIsReactElementClass = typeof this.type !== 'string';
8286

83-
if (DEBUG) { console.log('ReactNode > tryResolveTypeIsReactElementClass > type:', this.typeName); }
87+
if (DEBUG) {
88+
console.log('ReactNode > tryResolveTypeIsReactElementClass > type:', this.typeName);
89+
}
8490
}
8591
}
8692

8793
setAttribute(name: string, value: any) {
8894
this.setAttributes({
89-
[name]: value
95+
[name]: value,
9096
});
9197
}
9298

@@ -96,7 +102,7 @@ export class ReactNode {
96102

97103
setProperty(name: string, value: any) {
98104
this.setProperties({
99-
[name]: value
105+
[name]: value,
100106
});
101107
}
102108

@@ -156,16 +162,20 @@ export class ReactNode {
156162
// parent.
157163
if (!isReactNode(this._parent)) {
158164
if (this.isDestroyPending && this._parent) {
159-
if (DEBUG) { console.log('ReactNode > render > destroy > node:', this.toString(), 'parent:', this.parent); }
165+
if (DEBUG) {
166+
console.log('ReactNode > render > destroy > node:', this.toString(), 'parent:', this.parent);
167+
}
160168
ReactDOM.unmountComponentAtNode(this._parent);
161169
return this;
162170
}
163171

164172
if (this.isRenderPending) {
165-
if (DEBUG) { console.log('ReactNode > render > node:', this.toString(), 'parent:', this.parent); }
173+
if (DEBUG) {
174+
console.log('ReactNode > render > node:', this.toString(), 'parent:', this.parent);
175+
}
166176
// It is expected that the element will be recreated and re-rendered with each attribute change.
167177
// See: https://reactjs.org/docs/rendering-elements.html
168-
ReactDOM.render(this.renderRecursive() as any, this._parent);
178+
ReactDOM.render(this.renderRecursive() as React.ReactElement<{}>, this._parent);
169179
this.isRenderPending = false;
170180
}
171181
}
@@ -174,10 +184,7 @@ export class ReactNode {
174184
}
175185

176186
private renderRecursive(key?: string): React.ReactElement<{}> | string {
177-
const children =
178-
this.children
179-
? this.children.map((child, index) => child.renderRecursive(index.toString()))
180-
: [];
187+
const children = this.children ? this.children.map((child, index) => child.renderRecursive(index.toString())) : [];
181188

182189
if (this.text) {
183190
return this.text;
@@ -187,11 +194,11 @@ export class ReactNode {
187194

188195
if (key) this.props['key'] = key;
189196

190-
const clearedProps = this.transformProps(
191-
removeUndefinedProperties(this.props)
192-
);
197+
const clearedProps = this.transformProps(removeUndefinedProperties(this.props));
193198

194-
if (DEBUG) { console.warn('ReactNode > renderRecursive > type:', this.toString(), 'props:', this.props, 'children:', children); }
199+
if (DEBUG) {
200+
console.warn('ReactNode > renderRecursive > type:', this.toString(), 'props:', this.props, 'children:', children);
201+
}
195202
return React.createElement(this.type, clearedProps, children.length > 0 ? children : undefined);
196203
}
197204

@@ -220,7 +227,14 @@ export class ReactNode {
220227

221228
// This is called by Angular core when projected content is being added.
222229
appendChild(projectedContent: HTMLElement) {
223-
if (DEBUG) { console.error('ReactNode > appendChild > node:', this.toString(), 'projectedContent:', projectedContent.toString().trim()); }
230+
if (DEBUG) {
231+
console.error(
232+
'ReactNode > appendChild > node:',
233+
this.toString(),
234+
'projectedContent:',
235+
projectedContent.toString().trim()
236+
);
237+
}
224238
this.childrenToAppend.push(projectedContent);
225239
}
226240

@@ -239,5 +253,4 @@ export class ReactNode {
239253

240254
return '[undefined ReactNode]';
241255
}
242-
243256
}

0 commit comments

Comments
 (0)