Skip to content

Instantly share code, notes, and snippets.

View rbiggs's full-sized avatar

Robert Biggs rbiggs

View GitHub Profile
@rbiggs
rbiggs / app.js
Last active September 5, 2017 22:31
Example of dynamic counters with Composi.
import {h, Component, uuid} from 'composi'
import {counters} from './counters'
import {Counter} from './counter'
import {counterSum} from './counterSum'
// Callback for adding counter
const addCounter = () => {
const counter = new Counter({
root: '#counter',
state: {disabled: false, number: 1, id: uuid(true)},
@rbiggs
rbiggs / app.js
Last active August 26, 2017 23:35
Example of clock with Composi
import {h, Component} from 'composi'
class Clock extends Component {
constructor(props) {
super(props)
this.state = {time: new Date()};
}
render() {
return (
@rbiggs
rbiggs / app.js
Last active August 27, 2017 00:12
SVG Seconds Clock with Composi
import {h, Component} from 'composi'
class Clock extends Component {
constructor(props) {
super(props)
this.state = {time: Date.now()}
this.styles = {
'p > span': {
fontFamily: 'Courier, Monospace'
}
@rbiggs
rbiggs / app.js
Created August 27, 2017 00:56
Toggle Button with Events -- Composi
import {h, Component} from 'composi'
class Toggle extends Component {
constructor(props) {
super(props);
this.state = {isToggleOn: true};
// This binding is necessary to make `this` work in the callback
this.handleClick = this.handleClick.bind(this);
}
@rbiggs
rbiggs / index.js
Last active September 5, 2017 22:29
Example of Custom Tags with props and Nesting with Composi
import {h, Component, injectElement} from 'composi'
function Welcome(props) {
return <h1>Hello, {props.name}.</h1>
}
const Button = (props) => <button>{dingo.label}</button>
function App() {
return (
<div>
@rbiggs
rbiggs / index.js
Last active September 5, 2017 22:30
Creating Composi Component without JSX: Hyperscript
import {h, Component, injectElement} from 'composi'
// Define hyperscript functions:
function Welcome(props) {
return h('h1', {}, `Hello, ${props.name}.`)
}
function App() {
return h(
'div', {}, [
@rbiggs
rbiggs / hello-world.js
Created September 6, 2017 00:11
Hello World same from default new project
import {h, Component} from 'composi'
const title = new Component({
root: 'header',
state: 'World',
render: (message) => (
<h1>Hello, {message}!</h1>
),
styles: {
padding: 20,
@rbiggs
rbiggs / person-component.js
Created September 6, 2017 02:19
Component that consumes an object.
import {h, Component} from 'composi'
const personData = {
name: {
first: 'Joe',
last: 'Bodoni'
},
age: 26,
job: 'mechanic'
}
const person = new Component({
@rbiggs
rbiggs / array-component.js
Last active September 6, 2017 02:43
A component that consumes an array
import {h, Component} from 'composi'
const fruits = [
'Apples', 'Oranges', 'Bananas', 'Strawberries'
]
const list = new Component({
root: 'section',
state: fruits,
// Use map on array of fruits:
@rbiggs
rbiggs / array-component.js
Created September 6, 2017 02:54
Component with array of objects
import {h, Component} from 'composi'
const fruits = [
{
name: 'Apples',
quanity: 6
},
{
name: 'Oranges',