Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimal example template? #22

Open
janwirth opened this issue Oct 26, 2024 · 10 comments
Open

Minimal example template? #22

janwirth opened this issue Oct 26, 2024 · 10 comments

Comments

@janwirth
Copy link

I want ts-liveview as UI for a scraper. I don't need a database because I bring my own. Is there minimal example template that I can use - using an interval timer in JS?

@beenotung
Copy link
Owner

This is a great suggestion, I'll reduce a minimal template setup without database.

@beenotung
Copy link
Owner

In the meantime, you may use the "minimal template" and remove the database related parts.

When removing part of the functionality, you can get hints from tsc to clean up the rest by running "npm run type-check".

@beenotung
Copy link
Owner

Pull request is welcomed, and I'll work out that in parallel.

@beenotung
Copy link
Owner

A minimal template without database is released 🚀

If you cannot see it due to outdated npx cache, you can delete ~/.npm/_npx, or run npm init ts-liveview@latest

@beenotung
Copy link
Owner

@janwirth does the new minimal template without database setup suit your need?

@beenotung
Copy link
Owner

I've mentioned this minimal template without database in the readme.
Feel free to re-open the issue if it hasn't addressed your original suggestion.

@janwirth
Copy link
Author

janwirth commented Nov 1, 2024

Hey sorry i didn't get back to you! Thank you for responding to this so promptly. I will give it a try soon!

@janwirth
Copy link
Author

janwirth commented Nov 3, 2024

To be honest, I was just considering to look at this library for another use case, something that I will ship to production. Then I got worried about all of the scripts that I will need to understand and maintain. It's still not really 'minimal' to me. Minimal to me would be

import {liveview, useState} from 'ts-liveview'

import { Hono } from 'hono'
app.get('/', (c) => liveview.render(c, App))

const App = (ctx) => {
     const [counter, setCounter] = useState(0)
     return <div onPress={() => setCounter(counter + 1)}> {counter} {ctx.sessionId} </div>
}

Please don't get me wrong, I appreciate the work and I'm really impressed and want to use it, but I'm time-constrained so I can not understand what looks like internals of a framework to me :)

@beenotung
Copy link
Owner

beenotung commented Nov 18, 2024

@janwirth I see what you're looking for.

This project is structured as a starter template, instead of a framework or library to be imported.

The rational behind is to enable free form of extension, modification, and shrinking unused parts without forking the library.

This design however does take more initial mental workload to understand than using a framework / library that expose a API to start with (like express and react).

Without changing the "internal" or backbone of ts-liveview, the first file to edit is usually the home.tsx file.

When you want to add more pages, you can run ./scripts/new-route.sh, which will create a new file inside server/app/pages, and auto open it in the IDE. It also auto updates the server/app/routes.tsx for the routing setup.


Is it not mutually exclusive to have ts-liveview as a starter template at the same time to be available on npm. I will include this option so it can be easier to start with.

Thanks for the suggestion.

@beenotung beenotung reopened this Nov 18, 2024
@janwirth
Copy link
Author

What I also noticed is that you are streaming individual HTML updates a là jQuery to the client:

https://github.com/beenotung/ts-liveview/blob/master/server/app/pages/calculator.tsx#L5

I was in fact looking for something that allows me to define JSX and have the server state update the client automatically. I see that there are imperative modifications streamed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants