This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const someProxy = new Proxy(targetObject, handler); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* SAMPLE DATA */ | |
const DATA = [ | |
{ | |
id: "1", | |
name: "Super mega mall", | |
address: "Some address 1", | |
city: "Super Mega City", | |
services: ["restaurant", "caffee", "shops", "cinema", "arcade"] | |
}, | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* UTILS */ | |
const getAverageScore = (score) => | |
score.length ? score.reduce((acc, point) => acc + point) / score.length : 0; | |
/* PROXY */ | |
const handleSet = (obj, prop, value) => { | |
const isNumber = !isNaN(parseInt(prop)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface User { | |
firstName: string; | |
middleName?: string; | |
lastName: string; | |
email: string; | |
balance: number; | |
currency: string; | |
locale: string; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface User { | |
firstName: string; | |
middleName?: string; | |
lastName: string; | |
email: string; | |
balance: number; | |
currency: string; | |
locale: string; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface User { | |
firstName: string; | |
middleName?: string; | |
lastName: string; | |
email: string; | |
balance: number; | |
currency: string; | |
locale: string; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* PROXY */ | |
const handleGet = (obj, prop) => { | |
if (prop === "undo") { | |
const last = obj.history.pop(); | |
if (!last) { | |
return; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* PROXY */ | |
const handleSet = (obj, prop, value) => { | |
if (prop === "content" && value.length > 0 && value.length < 255) { | |
const { content, lastUpdated, history = [] } = obj; | |
const historyUpdated = [...history, { content, lastUpdated }]; | |
if (content && lastUpdated) { | |
Reflect.set(obj, "history", historyUpdated); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* UTILS */ | |
const getFullName = (firstName, lastName, middleName) => | |
[firstName, middleName, lastName].filter((n) => !!n).join(" "); | |
const getFormattedBalance = (locale, currency, value) => { | |
return new Intl.NumberFormat(locale, { | |
style: "currency", | |
currency | |
}).format(value); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* UTILS */ | |
const getFullName = (firstName, lastName, middleName) => | |
[firstName, middleName, lastName].filter((n) => !!n).join(" "); | |
const getFormattedBalance = (locale, currency, value) => { | |
return new Intl.NumberFormat(locale, { | |
style: "currency", | |
currency | |
}).format(value); |
NewerOlder