- Determine your states
- Determine your events
- Determine your side effects (resulting changes in state)
You can store information in two ways:
- State nodes (each state node can have one value)
- Context (can hold arbitrary values because js object)
var form = document.querySelector('form'); | |
form.addEventListener('submit', function(event) { | |
event.preventDefault(); | |
submitForm(); | |
} | |
function submitForm(form) { | |
var data = serializeForm(form); | |
var json = JSON.stringify(data); | |
var xhr = requestPost(url, json); |
const f = useMemo(() => { | |
try { | |
return new Function('inputs', `return ${expression}`); | |
} catch (e) { | |
return [e]; | |
} | |
}, [expresssion]); | |
// input atoms |
const express = require('express'); | |
const htm = require('htm'); | |
const vhtml = require('vhtml'); | |
// create an html`` tag function for vhtml: | |
const html = htm.bind(vhtml); | |
const App = (props) => html` | |
<div class="app"> | |
<h1>This is an app</h1> |
function useFormik(props) { | |
// useState to keep the same observable around without recreating it on each render | |
const [formik] = React.useState(() => | |
mobx.observable({ | |
values: props.initialValues || {}, | |
touched: {} | |
}) | |
) | |
// just mutate state, this function itself can be considered an action+reducer |
import React, { | |
useContext, | |
createContext, | |
createElement, | |
useEffect, | |
useRef, | |
useCallback, | |
useState, | |
} from 'react'; | |
import isEqual from 'react-fast-compare'; |
import * as t from 'io-ts' | |
import * as React from 'react' | |
import { render } from 'react-dom' | |
type Field = t.StringType | t.NumberType | t.BooleanType | |
interface Form extends t.InterfaceType<{ [key: string]: Field }> {} | |
const toReactElement = (f: Form | Field): React.ReactElement<any> => { | |
// f is a tagged union | |
switch (f._tag) { |
This script was inspired by this blog post - however I found the technique to be a little insufficient. Many thanks to Artem Butusov as I would not have been able to do this without his blog post.
This script is intended to be used with semantic-ui-react projects. If you are just using semantic-ui, then you may need to do some other troubleshooting... I don't know as I haven't tested. From what I can tell everything should work just fine.
This process is completely different from the one described in the blog post above. This script is intended to do everything for you - no manual copying or updating code is required. If you have already followed
$ sudo apt-get install zlib1g-dev uuid-dev libmnl-dev gcc make git autoconf autoconf-archive autogen automake pkg-config curl
$ cd ~ && git clone https://github.com/wohali/netdata
$ cd netdata && git checkout couchdb
$ sudo ./netdata-installer.sh
$ sudo vi /etc/netdata/python.d/couchdb.conf
and set admin username/password$ sudo service netdata restart
export function drained$<T>(pullStream: Function): Rx.Observable<T> { | |
return Rx.Observable.create(function subscribe(observer: Rx.Observer<T>) { | |
const drain = function drain(read: Function) { | |
read(null, function more(end: any | boolean, data: T) { | |
if (end === true) { | |
observer.complete(); | |
return; | |
} | |
if (end) { |