-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path4-dispose.js
More file actions
26 lines (20 loc) · 664 Bytes
/
4-dispose.js
File metadata and controls
26 lines (20 loc) · 664 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
'use strict';
// npm install @preact/signals-core --save
const { signal, effect } = require('@preact/signals-core');
// Task: rewrite code to use preact `effect` and `dispose`;
// implement iteration to increment total and print it
// until total become greater than PURCHASE_LIMIT,
// do not stop iteration after that but just prevent
// printing purchase total
const PURCHASE_LIMIT = 1600;
const electronics = [
{ name: 'Laptop', price: 1500 },
{ name: 'Keyboard', price: 100 },
{ name: 'HDMI cable', price: 10 },
];
const total = signal(0);
effect(() => {
console.log(electronics);
console.log({ total });
console.log({ PURCHASE_LIMIT });
});