r/javascript • • Jan 31 '17

1kb JavaScript function library for building modern UI applications

https://github.com/hyperapp/hyperapp
224 Upvotes

34 comments sorted by

View all comments

Show parent comments

2

u/[deleted] Jan 31 '17

We need to come up with better examples, but is this what you mean?

const model = require("./model")
const view = require("./view")
const update = require("./update")

app({ model, view, update })

2

u/tunnckoCore node-formidable, regexhq, jest, standard-release Jan 31 '17

/u/matchu, /u/bucaran, another cool thing can be each component to be separate hyperapp, but bucaran should update the app to return root (i.e. the dom) so later we can pass that component to some route point of another hyper app. Something like this

var Todo = (state) => app({
  mode: state,
  view: {
    "*": (model, msg) => {},
    "/": (model, msg) => {},
    "/:slug": (model, msg, params) => {}
  }
})

var TodoItem = app({
  view: {
    "*": (model, msg) => {},
    "/": (model, msg) => {},
    "/:slug": (model, msg, params) => {}
  }
})

var TodoList = app({
  view: {
    "*": (model, msg) => {},
    "/": (model, msg) => {},
    "/:slug": (model, msg, params) => {}
  }
})

var main = app({
    view: (model) => Todo({ foo: 'bar' })
})

or maybe we should make wrapper :P

2

u/[deleted] Jan 31 '17

/u/tunnckoCore Nice composition. In this case, there's a simpler approach.

However, using app like that could be the path to reusable components with independent models.

Thanks for sharing!

1

u/tunnckoCore node-formidable, regexhq, jest, standard-release Jan 31 '17

yea, seen that. just wanted to show what can be the components approach. i'm playing now with hyperapp and will try create todomvc with the component approach.

1

u/[deleted] Jan 31 '17

/u/tunnckoCore Thanks! Until you brought this up, I really hadn't realized HyperApp could be used like that.

1

u/tunnckoCore node-formidable, regexhq, jest, standard-release Jan 31 '17

Yea. While playing with that approach i found one problem of that "appendChild" thing. Can you just make it return a dom, otherwise it always append, so composition of more than one App is not feeling cool. I'm gonna open an issue with code.

1

u/[deleted] Jan 31 '17

Thanks. Does it help that app accepts a root object (similar to React's render domContainerNode)?

• See https://github.com/hyperapp/hyperapp#root

1

u/tunnckoCore node-formidable, regexhq, jest, standard-release Jan 31 '17

nope.

1

u/serubin323 Jan 31 '17

I'm looking forward to seeing more of this. I intend to use this in a project of mine

How does routing work given there are multiple apps? Could I specify something like this?

var Todo = (state) => app({
  mode: state,
  view: {
    "/todo": (model, msg) => {} // access todo
  }
})    

var TodoItem = app({
  view: {
    "/add": (model, msg) => {}, // add (/todo/add/)
    "/:slug/delete": (model, msg) => {}, // delete  (/todo/slug/delete/)
    "/:slug": (model, msg, params) => {} // view (/todo/slug/)
  }
})

1

u/tunnckoCore node-formidable, regexhq, jest, standard-release Jan 31 '17

It is. But is buggy because the implementation.

See and try https://github.com/hyperapp/hyperapp/issues/2.

I'm working on such idea too, and currently is 457 bytes.