mirror of https://github.com/Budibase/budibase.git
2 changed files with 19 additions and 17 deletions
@ -1,38 +1,42 @@ |
|||||
<script> |
<script> |
||||
import { createEventDispatcher } from 'svelte' |
import { createEventDispatcher } from "svelte" |
||||
import Colorpicker from "@budibase/colorpicker" |
import Colorpicker from "@budibase/colorpicker" |
||||
|
|
||||
const dispatch = createEventDispatcher(); |
const dispatch = createEventDispatcher() |
||||
|
|
||||
export let value |
export let value |
||||
|
|
||||
const WAIT = 150; |
const WAIT = 150 |
||||
|
|
||||
function throttle(callback, wait, immediate = false) { |
function throttle(callback, wait, immediate = false) { |
||||
let timeout = null |
let timeout = null |
||||
let initialCall = true |
let initialCall = true |
||||
|
|
||||
return function() { |
return function() { |
||||
const callNow = immediate && initialCall |
const callNow = immediate && initialCall |
||||
const next = () => { |
const next = () => { |
||||
callback.apply(this, arguments) |
callback.apply(this, arguments) |
||||
timeout = null |
timeout = null |
||||
} |
} |
||||
|
|
||||
if (callNow) { |
if (callNow) { |
||||
initialCall = false |
initialCall = false |
||||
next() |
next() |
||||
} |
} |
||||
|
|
||||
if (!timeout) { |
if (!timeout) { |
||||
timeout = setTimeout(next, wait) |
timeout = setTimeout(next, wait) |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
const onChange = throttle(e => { |
const onChange = throttle( |
||||
dispatch('change', e.detail) |
e => { |
||||
}, WAIT, true) |
dispatch("change", e.detail) |
||||
|
}, |
||||
|
WAIT, |
||||
|
true |
||||
|
) |
||||
</script> |
</script> |
||||
|
|
||||
<Colorpicker value={value || '#C4C4C4'} on:change={onChange} /> |
<Colorpicker value={value || '#C4C4C4'} on:change={onChange} /> |
||||
|
|||||
Loading…
Reference in new issue