Skip to content

Instantly share code, notes, and snippets.

View rbiggs's full-sized avatar

Robert Biggs rbiggs

View GitHub Profile
@rbiggs
rbiggs / .js
Created February 3, 2019 17:43
Update state from user input
<input type="text" oninput={ e => send({type: 'updateInputValue', value: e.target.value})} />
@rbiggs
rbiggs / .js
Created February 3, 2019 17:43
Structure for a message
{
type: 'newValue',
value: 'This is the new value!'
}
@rbiggs
rbiggs / .js
Last active October 25, 2019 03:09
Render a list component
view(state, send) {
return render(<List {...{ state, send }}/>, '#app')
}
@rbiggs
rbiggs / .js
Created February 3, 2019 17:41
List functional component
function List({ state, send }) {
return (
<div class="list-container">
<p>
<input type="text" />
<button class="add-item">Add</button>
</p>
<ul class="list">
{
state.fruits.map(item => <li key={item.key}>
@rbiggs
rbiggs / .js
Last active October 25, 2019 03:06
Program init returning state and an effect
init() {
// Return state to use in program:
return state
}
@rbiggs
rbiggs / .js
Last active October 25, 2019 03:10
Returning state in the program init method
init() {
// always return state:
return state
}
@rbiggs
rbiggs / .js
Created February 3, 2019 17:38
Basic program state for a list component
const state = {
newKey: 104,
inputValue: '',
fruits: [
{
key: 101,
value: 'Apples'
},
{
key: 102,
@rbiggs
rbiggs / .js
Created February 3, 2019 17:37
Running a Composi program
run(program)
@rbiggs
rbiggs / .js
Last active February 3, 2019 17:35
A basic Composi runtime program
const program = {
init() {
},
view(state, send) {
},
update(state, msg) {
},
@rbiggs
rbiggs / .js
Last active November 15, 2018 15:27
@composi/core runtime program -- Counter
// Counter for view:
function Counter({state, send}) {
return (
<p>
<button onclick={() => history.go(0)} id='reload-btn'>Restart</button>
<button class='counter' onclick={() => send()}>{state}</button>
</p>
)
}