Guest User

Untitled

a guest
Aug 27th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. import React from 'react'
  2. import { render } from 'react-dom'
  3. import { compose, map, prop, curry, reduce, pipe } from 'ramda'
  4.  
  5. const combine = curry((c, o) => x => (<div>{c(x)} {o(x)}</div>))
  6. const combineComponents = (...args) => {
  7. const [first, ...rest] = args
  8. return reduce((acc, c) => combine(acc, c), first, rest)
  9. }
  10.  
  11. const state = {
  12. year: '2016',
  13. title: 'Random stuff',
  14. todos: [{id:1, text: 'foo'}, { id:2, text: 'bar'}]
  15. }
  16.  
  17. const getTodos = prop('todos')
  18.  
  19. const Header = title => <h1>A Todo List: {title}</h1>
  20. const List = items => <ul>{items}</ul>
  21. const Item = todo => <li key={todo.id}>{todo.text}</li>
  22. const Footer = text => <div>{text}</div>
  23.  
  24. const TodoHeader = pipe(s => s.title, Header)
  25. const TodoList = pipe(getTodos, compose(List, map(Item)))
  26. const TodoFooter = pipe(s => s.year, Footer)
  27.  
  28. const App = combineComponents(TodoHeader, TodoList, TodoFooter)
  29. const result = render(<App {...state} />, document.getElementById('root'))
Add Comment
Please, Sign In to add comment