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

Export Spring interface #6070

Closed
razshare opened this issue Mar 10, 2021 · 0 comments
Closed

Export Spring interface #6070

razshare opened this issue Mar 10, 2021 · 0 comments

Comments

@razshare
Copy link

razshare commented Mar 10, 2021

Is your feature request related to a problem? Please describe.
I'm trying to export spring stores but I can't specify their types as Spring<...> for the external binding variables.

Describe the solution you'd like
Can the Spring interface be exported?

interface Spring<T> extends Readable<T>{
set: (new_value: T, opts?: SpringUpdateOpts) => Promise<void>;
update: (fn: Updater<T>, opts?: SpringUpdateOpts) => Promise<void>;
precision: number;
damping: number;
stiffness: number;
}

Use case

<!-- file: welcome.svelte -->
<!-- some unrelated markup -->
<div 
    class="circle"
    style="
        --x:{$x}px;
        --y:{$y}px;
    "
>r</div>
<!-- some more unrelated markup -->
<style>
.circle{
    --x:0;
    --y:0;
    top:var(--y);
    left:var(--x);
}
</style>
<script lang="ts">
//...
import { spring } from 'svelte/motion';

export let x = spring(0,{
    stiffness: 0.1,
    damping: 0.25
});
export let y = spring(0,{
    stiffness: 0.1,
    damping: 0.25
});
//...
onMount(()=>{
    document.addEventListener("mousemove",e=>{
        //some logic

        x.set(/*some value*/);
        y.set(/*some value*/);
    });
})
</script>

Being able to do this and specify types would be useful:

<!-- file: home.svelte -->
<Welcome bind:x bind:y/>
<script lang="ts">
import type { Spring } from 'svelte/motion';    // <=== this would be useful
import Welcome from './welcome.svelte';

let x:Spring<number>;
let y:Spring<number>;

//now I know for sure that x and y are Spring<number>
</script>

Same thing with Tweened:

interface Tweened<T> extends Readable<T> {
set(value: T, opts?: Options<T>): Promise<void>;
update(updater: Updater<T>, opts?: Options<T>): Promise<void>;
}

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

1 participant