You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 3, 2022. It is now read-only.
<metaname="description" content="Composi is a JavaScript library for creating component-based interfaces. It uses the virtual dom to make efficient updates to the DOM based on a component's data or state.">
9
+
<metaname="description" content="Composi is a JavaScript library for creating component-based interfaces. It uses the virtual DOM to make efficient updates to the DOM based on a component's data or state.">
<pclass="docs__intro">Composi is the gradual evolution of front-end development since 2007. Its genesis was in the library <atarget='__blank' href="http://chocolatechip-ui.github.io">ChocolateChip-UI</a>. As an experiment, we took the component API from ChocolateChip-UI and combined it with a small and fast virtual dom. The result was Composi. Because of the virtual dom, when you change the state or data that a component uses, it updates automatically.</p>
63
+
<pclass="docs__intro">Composi is the gradual evolution of front-end development since 2007. Its genesis was in the library <atarget='__blank' href="http://chocolatechip-ui.github.io">ChocolateChip-UI</a>. As an experiment, we took the component API from ChocolateChip-UI and combined it with a small and fast virtual DOM. The result was Composi. Because of the virtual DOM, when you change the state or data that a component uses, it updates automatically.</p>
64
64
<h2>Composi is Small</h2>
65
-
<p>Although only <code>3KB</code>, Composi includes everything you need to create complex components. The Composi virtual dom code is less that <code>1KB</code>. It will only update the parts of the DOM that do not match the current state of a component. If you try to render a component with the same data again, no update will occur.</p>
65
+
<p>Although only <code>3KB</code>, Composi includes everything you need to create complex components. The Composi virtual DOM code is less that <code>1KB</code>. It will only update the parts of the DOM that do not match the current state of a component. If you try to render a component with the same data again, no update will occur.</p>
66
66
67
67
<h2>Composi Works Well with Others</h2>
68
68
<p>Composi was designed to be used with other libraries. You can use Lodash, Ramda, Boostrap, Material Design Lite, Redux, Mobx and other third party libraries with Composi. You can also use jQuery plugins in the same document. You cannot use jQuery on a Composi component. You can use any pubsub library to implement communication between jQuery plugins and Composi components.</p>
69
69
70
70
<h2>Similar to React</h2>
71
-
<p>Composi shares some features and many development patterns with React, Preact and Inferno. All have a Component class and a virtual dom. However, Composi is not a React clone. Internally it works quite differently. Most of the similarities arrise from the use of JSX. Composi's Component class shares some naming conventions with React.Component. Both have a <code>render</code> function, which works basically the same. It takes some data and returns some markup that gets converted into a virtual node. With React and friends, you pass a component class definition to the <code>render</code> function along with an elemement in which you want to insert it. This is completely unnecessary with Composi components. Instead you define a container property directly in the component definition.</p>
71
+
<p>Composi shares some features and many development patterns with React, Preact and Inferno. All have a Component class and a virtual DOM. However, Composi is not a React clone. Internally it works quite differently. Most of the similarities arrise from the use of JSX. Composi's Component class shares some naming conventions with React.Component. Both have a <code>render</code> function, which works basically the same. It takes some data and returns some markup that gets converted into a virtual node. With React and friends, you pass a component class definition to the <code>render</code> function along with an elemement in which you want to insert it. This is completely unnecessary with Composi components. Instead you define a container property directly in the component definition.</p>
72
72
<h2>Lifecycle Methods</h2>
73
73
<p>All of these have lifecycle methods. The React family generally has the following ones:</p>
<metaname="description" content="Composi is a JavaScript library for creating component-based interfaces. It uses the virtual dom to make efficient updates to the DOM based on a component's data or state.">
9
+
<metaname="description" content="Composi is a JavaScript library for creating component-based interfaces. It uses the virtual DOM to make efficient updates to the DOM based on a component's data or state.">
<metaname="description" content="Composi is a JavaScript library for creating component-based interfaces. It uses the virtual dom to make efficient updates to the DOM based on a component's data or state.">
9
+
<metaname="description" content="Composi is a JavaScript library for creating component-based interfaces. It uses the virtual DOM to make efficient updates to the DOM based on a component's data or state.">
@@ -76,7 +76,7 @@ <h2>Creating an Instance of Component</h2>
76
76
77
77
<p>Let's look at the first option, creating an instance of <code>Component</code>. When creating a component, you need to provide at least two arguments: the <code>container</code>, which is the element into which the component will be rendered and a render function. The <code>container</code> could just be the document body. Or you could have a basic html shell with predefined containers into which you will render your components. Using a shell means your document reaches first render quicker. </p>
78
78
79
-
<p>The component's <code>render</code> function is used to define markup that will get converted into elements and inserted into the DOM. The render function is also used every time the component is updated. Rendering the component with new data or changing the state of a stateful component causes the component use this render function to create a new virtual dom. Composi compares the component's new virtual dom with its previous one. If they do not match, the new one is used to patch and update the DOM. This results in fast and efficient updating of the DOM based on current state.</p>
79
+
<p>The component's <code>render</code> function is used to define markup that will get converted into elements and inserted into the DOM. The render function is also used every time the component is updated. Rendering the component with new data or changing the state of a stateful component causes the component use this render function to create a new virtual DOM. Composi compares the component's new virtual DOM with its previous one. If they do not match, the new one is used to patch and update the DOM. This results in fast and efficient updating of the DOM based on current state.</p>
80
80
81
81
<p>By default Composi uses <code>JSX</code> for markdown. You can learn more about <code>JSX</code> in the <ahref='./jsx.md' target='__blank'>documentation</a>. If you prefer, you can use the hyperscript function <ahref='./hyperscript.md' target='__blank'>h</a> to define your markup. For the purpose of this tutorial we're going to use <code>JSX</code> for simplicity's sake.</p>
<metaname="description" content="Composi is a JavaScript library for creating component-based interfaces. It uses the virtual dom to make efficient updates to the DOM based on a component's data or state.">
9
+
<metaname="description" content="Composi is a JavaScript library for creating component-based interfaces. It uses the virtual DOM to make efficient updates to the DOM based on a component's data or state.">
<metaname="description" content="Composi is a JavaScript library for creating component-based interfaces. It uses the virtual dom to make efficient updates to the DOM based on a component's data or state.">
9
+
<metaname="description" content="Composi is a JavaScript library for creating component-based interfaces. It uses the virtual DOM to make efficient updates to the DOM based on a component's data or state.">
<metaname="description" content="Composi is a JavaScript library for creating component-based interfaces. It uses the virtual dom to make efficient updates to the DOM based on a component's data or state.">
9
+
<metaname="description" content="Composi is a JavaScript library for creating component-based interfaces. It uses the virtual DOM to make efficient updates to the DOM based on a component's data or state.">
<metaname="description" content="Composi is a JavaScript library for creating component-based interfaces. It uses the virtual dom to make efficient updates to the DOM based on a component's data or state.">
9
+
<metaname="description" content="Composi is a JavaScript library for creating component-based interfaces. It uses the virtual DOM to make efficient updates to the DOM based on a component's data or state.">
<p>When you create components with the Component class, you have a reference for the component's properties, methods, etc. This also provides a point of reference for the virtual dom. In contrast, functional components do not have this reference for their virtual dom. Instead, with functional components, the scope in which the function is invoked becomes the scope for the virtual dom. This means as your project grows and code gets out over many files, the scope of a functional component can be spread across several files. For components this is not a problem. For functional components this means the first time it gets invoked in a new scope, the previous virtual dom will be replaced by a new one. Unless you are creating a list with 10,000 or more items, you won't notice any inefficencies. However, it does result in more layout thrashing than when creating class-based components.</p>
67
+
<p>When you create components with the Component class, you have a reference for the component's properties, methods, etc. This also provides a point of reference for the virtual DOM. In contrast, functional components do not have this reference for their virtual DOM. Instead, with functional components, the scope in which the function is invoked becomes the scope for the virtual DOM. This means as your project grows and code gets out over many files, the scope of a functional component can be spread across several files. For components this is not a problem. For functional components this means the first time it gets invoked in a new scope, the previous virtual DOM will be replaced by a new one. Unless you are creating a list with 10,000 or more items, you won't notice any inefficencies. However, it does result in more layout thrashing than when creating class-based components.</p>
68
68
69
69
<h2>Creating Functional Components</h2>
70
70
<p>Functional components use <ahref='./jsx.md'>JSX</a> to create markup, but technically you could also use [Hyperx-ES6](https://www.npmjs.com/package/hyperx-es6) with ES6 template literals. Here we're going to look at using JSX.</p>
<p>As you can see above, we need to get the value of the input. If the value is truthy, we push it to the items array. Then we re-render the functional component list. Because this is a different scope than <code>app.js</code> where we initially rendered the list, the first time we add an item, the list will be created a new, replacing what was there. That's because this is a different scope than <code>app.js</code>. However, with every new addition, the render function will use the new virtual dom in this scope to patch the DOM efficiently.</p>
304
+
<p>As you can see above, we need to get the value of the input. If the value is truthy, we push it to the items array. Then we re-render the functional component list. Because this is a different scope than <code>app.js</code> where we initially rendered the list, the first time we add an item, the list will be created a new, replacing what was there. That's because this is a different scope than <code>app.js</code>. However, with every new addition, the render function will use the new virtual DOM in this scope to patch the DOM efficiently.</p>
305
305
306
306
<h2>Using the handleEvent Object</h2>
307
307
<p>Now that we have our <code>handleEvent</code> object defined, we need to wire it up to our component. We'll do that in our <code>app.js</code> file:</p>
@@ -310,7 +310,7 @@ <h2>Using the handleEvent Object</h2>
310
310
<p>Codepen Example:</p>
311
311
<pdata-height="450" data-theme-id="6688" data-slug-hash="YEPPJz" data-default-tab="js,result" data-user="rbiggs" data-embed-version="2" data-pen-title="Composi functional-components-4" class="codepen">See the Pen <ahref="https://codepen.io/rbiggs/pen/YEPPJz/">Composi functional-components-4</a> by Robert Biggs (<ahref="https://codepen.io/rbiggs">@rbiggs</a>) on <ahref="https://codepen.io">CodePen</a>.</p>
<p>And that's it. With that we now have an interactive functional component that updates in real time with a virtual dom.</p>
313
+
<p>And that's it. With that we now have an interactive functional component that updates in real time with a virtual DOM.</p>
314
314
315
315
<h2>Inline Events</h2>
316
316
<p>We could also create a functional component with inline events. We're going to take our interactive list from above and take it to the next level. We'll let the user also delete items. We'll considate all the sub-components into one. We'll also add in private event handlers for the inline events. We've bundled this all up as a Codepen example:</p>
<p>Although you can build a complex app using nothing but functional components, there are certain conveniences when using the Component class. First and foremost is the fact that classes allow you to encapsulate functionality using properties and methods defined directly on the component. The second is the component itself enables more efficient use of the virtual dom because it keeps track of that internally. Because of this, you can have multiple class components in the same container. With functional components, because the virtual dom is created and handle by the <code>render</code> function, there can only be one functional component in each container.</p>
367
+
<p>Although you can build a complex app using nothing but functional components, there are certain conveniences when using the Component class. First and foremost is the fact that classes allow you to encapsulate functionality using properties and methods defined directly on the component. The second is the component itself enables more efficient use of the virtual DOM because it keeps track of that internally. Because of this, you can have multiple class components in the same container. With functional components, because the virtual DOM is created and handle by the <code>render</code> function, there can only be one functional component in each container.</p>
<metaname="description" content="Composi is a JavaScript library for creating component-based interfaces. It uses the virtual dom to make efficient updates to the DOM based on a component's data or state.">
9
+
<metaname="description" content="Composi is a JavaScript library for creating component-based interfaces. It uses the virtual DOM to make efficient updates to the DOM based on a component's data or state.">
0 commit comments