Browse Source

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

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

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

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

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

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

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

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

Loading…
Cancel
Save