Skip to content

Commit 4211ab0

Browse files
committed
Improve the props-driven approach
1 parent 6adafdf commit 4211ab0

File tree

4 files changed

+37
-6
lines changed

4 files changed

+37
-6
lines changed

PROPS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
## Props-driven components

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@ const Square = props => [
4545

4646
There is no transpilation phase, the sources are directly used by the browser in the form of ES modules.
4747

48+
## Props-driven
49+
50+
All the components receive props from the parent in a form of an object.
51+
These props are the single source of truth for each and every component. The props define what given component renders.
52+
53+
All simple components, based only on props, always render the same template for the same set of props.
54+
55+
Elements get props transformed into properties, attributes and listeners set on the element instance.
56+
57+
Web Components are also driven by props, but they can fetch supplementary data if necessary.
58+
Supplemented props object is stored as internal state, which feeds the rendered content.
59+
60+
More about props-driven components [here](PROPS.md).
61+
4862
## State management
4963

5064
Instead of using the centralized state, as in Redux, Web Component manages only the view model that is necessary

src/core/virtual-dom.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ limitations under the License.
4646
if (ComponentClass.prototype instanceof opr.Toolkit.WebComponent) {
4747
return this.createWebComponent(
4848
description, parent && parent.rootNode, context,
49-
/*= requireCustomElement */ true);
49+
/*= requireCustomElement */ false);
5050
}
5151
const component = new ComponentClass(description, parent, context);
5252
const nodeDescription = opr.Toolkit.Renderer.render(

test/functional/components.test.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
describe.skip('Components', () => {
1+
describe.only('Components', () => {
2+
23
let container;
34

45
beforeEach(() => {
@@ -8,12 +9,27 @@ describe.skip('Components', () => {
89

910
afterEach(() => { container.remove(); })
1011

11-
it('creates a simple Component', async () => {
12+
describe('=> Web Component', () => {
1213

13-
});
14+
it('renders custom element', async() => {
15+
16+
// given
17+
class CustomElement extends opr.Toolkit.WebComponent {
18+
19+
static elementName = 'custom-element';
20+
21+
render() {
22+
return [
23+
'main',
24+
];
25+
}
26+
}
1427

15-
// drive
16-
it('creates a Web Component', async () => {
28+
// when
29+
const element = await opr.Toolkit.render(CustomElement, container);
1730

31+
// then
32+
assert.equal(element.ref.tagName, 'CUSTOM-ELEMENT');
33+
})
1834
});
1935
});

0 commit comments

Comments
 (0)