Skip to content

Commit 61773e6

Browse files
committed
2 parents ecb4bf1 + 4b2d82d commit 61773e6

File tree

41 files changed

+982
-985
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+982
-985
lines changed

1-js/99-js-misc/01-proxy/01-error-nonexisting/task.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
# Error on reading non-existent property
1+
# Errore in lettura di una proprietà non esistente
22

3-
Usually, an attempt to read a non-existent property returns `undefined`.
3+
Solitamente, un tentativo di accesso ad una proprietà non esistente ritorna `undefined`.
44

5-
Create a proxy that throws an error for an attempt to read of a non-existent property instead.
5+
Create un proxy che generi un errore ad ogni tentativo di accesso ad una proprietà non esistente.
66

7-
That can help to detect programming mistakes early.
7+
Questo può aiutare a trovare errori di programmazione in anticipo.
88

9-
Write a function `wrap(target)` that takes an object `target` and return a proxy that adds this functionality aspect.
9+
Scrivete una funzione `wrap(target)` che prende un oggetto `target` e ne ritorna un proxy con la funzionalità appena descritta.
1010

11-
That's how it should work:
11+
Ecco come dovrebbe funzionare:
1212

1313
```js
1414
let user = {
@@ -18,7 +18,7 @@ let user = {
1818
function wrap(target) {
1919
return new Proxy(target, {
2020
*!*
21-
/* your code */
21+
/* il vostro codice */
2222
*/!*
2323
});
2424
}

1-js/99-js-misc/01-proxy/02-array-negative/solution.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ let array = [1, 2, 3];
55
array = new Proxy(array, {
66
get(target, prop, receiver) {
77
if (prop < 0) {
8-
// even if we access it like arr[1]
9-
// prop is a string, so need to convert it to number
8+
// anche se vi accediamo come arr[1]
9+
// prop è una stringa, quindi dobbiamo convertirla a number
1010
prop = +prop + target.length;
1111
}
1212
return Reflect.get(target, prop, receiver);
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11

2-
# Accessing array[-1]
2+
# Accesso ad un array[-1]
33

4-
In some programming languages, we can access array elements using negative indexes, counted from the end.
4+
In alcuni linguaggi di programmazione, possiamo accedere agli elementi dell'array utilizzando indici negativi, che iniziano il conteggio dalla coda dell'array.
55

6-
Like this:
6+
Come nell'esempio:
77

88
```js
99
let array = [1, 2, 3];
1010

11-
array[-1]; // 3, the last element
12-
array[-2]; // 2, one step from the end
13-
array[-3]; // 1, two steps from the end
11+
array[-1]; // 3, l'ultimo elemento
12+
array[-2]; // 2, il penultimo elemento
13+
array[-3]; // 1, il terzultimo elemento
1414
```
1515

16-
In other words, `array[-N]` is the same as `array[array.length - N]`.
16+
In altre parole, `array[-N]` equivale a `array[array.length - N]`.
1717

18-
Create a proxy to implement that behavior.
18+
Create un proxy che implementa questa funzionalità.
1919

20-
That's how it should work:
20+
Ecco come dovrebbe funzionare:
2121

2222
```js
2323
let array = [1, 2, 3];
2424

2525
array = new Proxy(array, {
26-
/* your code */
26+
/* il vostro codice */
2727
});
2828

2929
alert( array[-1] ); // 3
3030
alert( array[-2] ); // 2
3131

32-
// Other array functionality should be kept "as is"
32+
// Le altre funzionalità dell'array devono rimanere inalterate
3333
```

1-js/99-js-misc/01-proxy/03-observable/solution.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
The solution consists of two parts:
1+
La soluzione consiste di due parti:
22

3-
1. Whenever `.observe(handler)` is called, we need to remember the handler somewhere, to be able to call it later. We can store handlers right in the object, using our symbol as the property key.
4-
2. We need a proxy with `set` trap to call handlers in case of any change.
3+
1. Quando `.observe(handler)` viene invocato, dobbiamo memorizzare l'handler da qualche parte, per poter essere in grado di invocarlo più tardi. Possiamo memorizzare gli handler nell'oggetto, utilizzando un symbol come chiave della proprietà.
4+
2. Abbiamo bisogno di un proxy con la trappola `set` per poter invocare gli handlers in caso di cambiamenti.
55

66
```js run
77
let handlers = Symbol('handlers');
88

99
function makeObservable(target) {
10-
// 1. Initialize handlers store
10+
// 1. Inizializziamo lo store per gli handlers
1111
target[handlers] = [];
1212

13-
// Store the handler function in array for future calls
13+
// Memorizziamo l'handler nell'array per poterlo invocare successivamente
1414
target.observe = function(handler) {
1515
this[handlers].push(handler);
1616
};
1717

18-
// 2. Create a proxy to handle changes
18+
// 2. Creiamo un proxy per gestire le modifiche
1919
return new Proxy(target, {
2020
set(target, property, value, receiver) {
21-
let success = Reflect.set(...arguments); // forward the operation to object
22-
if (success) { // if there were no error while setting the property
23-
// call all handlers
21+
let success = Reflect.set(...arguments); // inoltriamo l'operazione all'oggetto
22+
if (success) { // se non è stato generato alcun errore durante il cambiamento della proprietà
23+
// invochiamo tutti gli handlers
2424
target[handlers].forEach(handler => handler(property, value));
2525
}
2626
return success;
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11

22
# Observable
33

4-
Create a function `makeObservable(target)` that "makes the object observable" by returning a proxy.
4+
Create una funzione `makeObservable(target)` che "rende l'oggetto osservabile" ritornandone un proxy.
55

6-
Here's how it should work:
6+
Ecco come dovrebbe funzionare:
77

88
```js run
99
function makeObservable(target) {
10-
/* your code */
10+
/* il vostro codice */
1111
}
1212

1313
let user = {};
@@ -20,8 +20,8 @@ user.observe((key, value) => {
2020
user.name = "John"; // alerts: SET name=John
2121
```
2222

23-
In other words, an object returned by `makeObservable` is just like the original one, but also has the method `observe(handler)` that sets `handler` function to be called on any property change.
23+
In altre parole, un oggetto ritornato da `makeObservable` equivale a quello originale, ma possiede il metodo `observe(handler)` che imposta la funzione `handler` per essere invocata quando una qualsiasi proprietà cambia.
2424

25-
Whenever a property changes, `handler(key, value)` is called with the name and value of the property.
25+
Quando una proprietà verrà modificata, `handler(key, value)` verrà invocato con il nome ed il valore della proprietà.
2626

27-
P.S. In this task, please only take care about writing to a property. Other operations can be implemented in a similar way.
27+
P.S. In questo task, gestite solamente la scrittura della proprietà. Le altre operazioni possono essere implementate in maniera simile.

0 commit comments

Comments
 (0)