mirror of https://github.com/sveltejs/svelte
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
423 B
23 lines
423 B
5 years ago
|
<script context="module">
|
||
|
let value = 'Blub';
|
||
|
let count = 0;
|
||
|
const subscribers = new Set();
|
||
|
export const model = {
|
||
|
subscribe(fn) {
|
||
|
subscribers.add(fn);
|
||
|
count ++;
|
||
|
fn(value);
|
||
|
return () => {
|
||
|
count--;
|
||
|
subscribers.delete(fn);
|
||
|
};
|
||
|
},
|
||
|
set(v) {
|
||
|
value = v;
|
||
|
subscribers.forEach(fn => fn(v));
|
||
|
},
|
||
|
getCount() {
|
||
|
return count;
|
||
|
}
|
||
|
};
|
||
|
</script>
|