Last active
December 28, 2021 08:18
-
-
Save busypeoples/a1a26365a635e6c08c3fa690c98ed09a to your computer and use it in GitHub Desktop.
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 React from 'react' | |
import { render } from 'react-dom' | |
import { compose, map, prop, curry, reduce, pipe } from 'ramda' | |
const combine = curry((c, o) => x => (<div>{c(x)} {o(x)}</div>)) | |
const combineComponents = (...args) => { | |
const [first, ...rest] = args | |
return reduce((acc, c) => combine(acc, c), first, rest) | |
} | |
const state = { | |
year: '2016', | |
title: 'Random stuff', | |
todos: [{id:1, text: 'foo'}, { id:2, text: 'bar'}] | |
} | |
const getTodos = prop('todos') | |
const Header = title => <h1>A Todo List: {title}</h1> | |
const List = items => <ul>{items}</ul> | |
const Item = todo => <li key={todo.id}>{todo.text}</li> | |
const Footer = text => <div>{text}</div> | |
const TodoHeader = pipe(s => s.title, Header) | |
const TodoList = pipe(getTodos, compose(List, map(Item))) | |
const TodoFooter = pipe(s => s.year, Footer) | |
const App = combineComponents(TodoHeader, TodoList, TodoFooter) | |
const result = render(<App {...state} />, document.getElementById('root')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I really love this, however, one thing I note @busypeoples is that type checking gets lost e.g. adding some dummy type like:
...doesn't result in a warning about failed prop type?