question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

External view files

See original GitHub issue

Hello there!

First of all i’d like to say that i’m super excited with this project! It’s by far the most awesome front-end framework that i’ve seen in a long time!

I come from a backend background and i usually don’t play nice with frontend standards, but i’m getting used to it…

I’d like to know how to use a separated .html file from the view, cause i can’t deal with html and js in the same file, seems so dirty… 😦

What i’m looking for would be something like:

app.js

const choo = require('choo')
const app = choo()

app.model({
  state: { title: 'Set the title' },
  reducers: {
    update: (action, state) => ({ title: action.value })
  }
})

const mainTemplate = require('./template.html');
const mainView = (params, state, send) => choo.view(mainTemplate)

app.router((route) => [
  route('/', mainView)
])

const tree = app.start()
document.body.appendChild(tree)

template.html

<main>
    <h1>${state.title}</h1>
    <input
      type="text"
      oninput=${(e) => send('update', { value: e.target.value })}>
 </main>

is there anything similar to this?

best, rafa

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
timwiscommented, Jul 4, 2016

@rafaelamorim Believe me I know the feeling - there’s some really awful code out there where JS generates HTML markdown and it starts to feel really unmaintainable. But here are some things to consider:

  1. It’s actually completely valid vanilla javascript - there is no magical transpilation happening like with JSX
  2. You can put your view function in its own file and think of it as your template file, just with a different file extension, and a module.exports = (params, state, send) => {} wrapper around it
  3. All the cool kids are doing it
2reactions
rafaismynamecommented, Jul 7, 2016

YEP! it’s a “get used to that kid” case 😉 Thanks to everyone that helped me out on that.

Keep on the awesome work guys! You guys rock!

Best, Rafa

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to View the Contents of a Hard Drive
Viewing All Files · 1. Click "Organize" in the Windows Explorer toolbar and select "Folder and Search Options." · 2. Click the "View"...
Read more >
Move your files to a new Windows PC using an external ...
Learn how to move files to a new Windows PC using an external storage device ... hold (or right-click) the folders, then select...
Read more >
Solved: Hard Drive Not Showing Files Though They Still Exist
Don't worry if your external or internal hard drive is not showing files though they still exist. First, download EaseUS file recovery software ......
Read more >
Solved – Files Not Showing In External Hard Drive [2022 ...
Open File Explorer the way you like. · Select View from the menu bar. · Click Options and choose Change folder and search...
Read more >
Solved - Can't See Files in External Hard Drive - YouTube
This video tells how to show hidden files in external hard drive and how to recover effectively and quickly recover lost data with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found