Browse Source

optimize EveryMinute by binding a variable instead of listening to an event.

main
Gisle Aune 4 years ago
parent
commit
0a7d342e86
  1. 6
      svelte-ui/src/components/DaysLeft.svelte
  2. 10
      svelte-ui/src/components/EveryMinute.svelte
  3. 8
      svelte-ui/src/components/GoalEntry.svelte

6
svelte-ui/src/components/DaysLeft.svelte

@ -19,10 +19,6 @@ import EveryMinute from "./EveryMinute.svelte";
return `${time.getFullYear()}-${pad(time.getMonth()+1)}-${pad(time.getDate())}` return `${time.getFullYear()}-${pad(time.getMonth()+1)}-${pad(time.getDate())}`
} }
function onMinute(e: {detail: Date}) {
now = e.detail;
}
$: { $: {
overdue = false; overdue = false;
unit = "days"; unit = "days";
@ -69,7 +65,7 @@ import EveryMinute from "./EveryMinute.svelte";
} }
</script> </script>
<EveryMinute on:minute={onMinute} />
<EveryMinute bind:now={now} />
<span title={titleTimeStr}> <span title={titleTimeStr}>
{#if (overdue)} {#if (overdue)}
<span class="overdue">{amountStr} {unit} ago</span> <span class="overdue">{amountStr} {unit} ago</span>

10
svelte-ui/src/components/EveryMinute.svelte

@ -10,12 +10,16 @@
<script lang="ts"> <script lang="ts">
import { createEventDispatcher, onMount } from "svelte";
import { onMount } from "svelte";
const dispatch = createEventDispatcher();
export let now: Date | number;
function onMinute(date: Date) { function onMinute(date: Date) {
dispatch("minute", date);
if (typeof(now) === "number") {
now = date.getTime();
} else {
now = date;
}
} }
onMount(() => { onMount(() => {

8
svelte-ui/src/components/GoalEntry.svelte

@ -17,10 +17,6 @@ import EveryMinute from "./EveryMinute.svelte";
let msElapsed: number; let msElapsed: number;
let now = Date.now(); let now = Date.now();
function onMinute(e: {detail: Date}) {
now = e.detail.getTime();
}
$: mdGoalEdit = {name:"goal.edit", goal}; $: mdGoalEdit = {name:"goal.edit", goal};
$: mdGoalDelete = {name:"goal.delete", goal}; $: mdGoalDelete = {name:"goal.delete", goal};
@ -40,7 +36,8 @@ import EveryMinute from "./EveryMinute.svelte";
} }
} }
</script> </script>
<EveryMinute on:minute={onMinute} />
<EveryMinute bind:now={now} />
<ParentEntry <ParentEntry
full={showAllOptions} full={showAllOptions}
entry={goal} entry={goal}
@ -57,6 +54,7 @@ import EveryMinute from "./EveryMinute.svelte";
<Progress thinner gray count={msElapsed} target={msLength} /> <Progress thinner gray count={msElapsed} target={msLength} />
</div> </div>
</ParentEntry> </ParentEntry>
<style> <style>
div.progress { div.progress {
padding-top: 0.125em; padding-top: 0.125em;

Loading…
Cancel
Save