Created
May 29, 2020 23:19
-
-
Save paul-snively/fbf3549c762a01366c98aa69271f5e9a to your computer and use it in GitHub Desktop.
TypeScript, Cycle.js, Fluent UI React
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Stream } from 'xstream'; | |
import { run } from "@cycle/run"; | |
import { ReactElement } from 'react'; | |
import { h, ReactSource } from "@cycle/react"; | |
import { makeDOMDriver, p } from "@cycle/react-dom"; | |
import { PrimaryButton, IStackTokens, Stack } from '@fluentui/react'; | |
export type Sources = { | |
readonly react: ReactSource; | |
}; | |
export type Sinks = { | |
readonly react: Stream<ReactElement>; | |
}; | |
function counter(sources: Sources): Sinks { | |
const click$ = (sources.react | |
.select("primary") | |
.events("click") as Stream<MouseEvent>) | |
.mapTo(+1) | |
const count$ = click$.fold((x, y) => x + y, 0) | |
const stackTokens: IStackTokens = { childrenGap: 40 }; | |
const content = count$.map(count => | |
h( | |
Stack, | |
{ | |
tokens: stackTokens, | |
}, | |
[ | |
h(PrimaryButton, {sel: "primary", text: "Primary"}), | |
p("Counter: " + count) | |
] | |
) | |
) | |
return { react: content } | |
} | |
const dispose = run(counter, { | |
react: makeDOMDriver(document.getElementById("root")) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment