Skip to content

SvelteDate.now() as a live updating source #12441

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

Closed
ottomated opened this issue Jul 15, 2024 · 6 comments
Closed

SvelteDate.now() as a live updating source #12441

ottomated opened this issue Jul 15, 2024 · 6 comments

Comments

@ottomated
Copy link
Contributor

ottomated commented Jul 15, 2024

Describe the problem

There's a lot of boilerplate required to make a $state that always refers to the current date.

Describe the proposed solution

It would be cool to be able to do this:

import { SvelteDate } from 'svelte/reactivity';

const time = $derived(
  new Date(SvelteDate.now()).toLocaleTimeString()
);

Naive REPL example

Importance

nice to have

@Conduitry
Copy link
Member

How often would this try to update? Every millisecond? I don't know how to do this automatically in a sane way.

@ottomated
Copy link
Contributor Author

ottomated commented Jul 15, 2024

How often would this try to update? Every millisecond? I don't know how to do this automatically in a sane way.

It would use svelte's internal requestAnimationFrame loop

@brunnerh
Copy link
Member

brunnerh commented Jul 15, 2024

Svelte does not have an update loop, it only updates the DOM when things have been changed, the change being the trigger.

@dummdidumm
Copy link
Member

I don't think this makes sense - it would bring down performance because it would update at an insane rate, when in reality you're likely only interested in every second/minute/etc. Much better to decide the interval yourself and trigger updates at the appropriate times.

@dummdidumm dummdidumm closed this as not planned Won't fix, can't repro, duplicate, stale Jul 15, 2024
@ottomated
Copy link
Contributor Author

Svelte does not have an update loop, it only updates the DOM when things have been changed, the change being the trigger.

Here's what I'm talking about: https://github.com/sveltejs/svelte/blob/main/packages/svelte/src/internal/client/loop.js

@brunnerh
Copy link
Member

That is for transitions/animations.

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

4 participants