This file contains hidden or 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
function deepFreeze(obj) { | |
Object.freeze(obj) | |
const propertiesList = Object.getOwnPropertyNames(obj) | |
propertiesList.forEach((key) => { | |
const isNotNullOrUndefined = | |
obj[key] !== null || typeof obj[key] !== 'undefined' | |
const hasOwnProperty = obj.hasOwnProperty(key) |
This file contains hidden or 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
class UsersLanguageAdapter { | |
constructor(lang = "en") { | |
this.language = lang; | |
this.languageMessages = { | |
add: { | |
en: "Added succefully", | |
fr: "Ajouté avec succès", | |
pt: "Adicionado com sucesso", | |
}, |
This file contains hidden or 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
class Users { | |
constructor(lang = "en") { | |
this.data = []; | |
this.language = lang; | |
this.languageMessages = { | |
add: { | |
en: "Added succefully", | |
fr: "Ajouté avec succès", |
This file contains hidden or 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
class Products { | |
constructor() { | |
this.data = []; | |
} | |
add(product) { | |
this.data.push(product); | |
return true; | |
} |
This file contains hidden or 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
class Products { | |
constructor() { | |
this.data = []; | |
} | |
add(product) { | |
this.data.push(product); | |
return true; | |
} |
This file contains hidden or 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
class Products { | |
constructor(User) { | |
if (typeof User !== "object") { | |
throw new Error("User object is required to initialize products class"); | |
return false; | |
} | |
this.currentUser = User; | |
this.data = []; | |
} |
This file contains hidden or 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 myCustomObj = { | |
even: { | |
frozen: { | |
thisObjectWillChange: "nope 😳", | |
}, | |
}, | |
}; | |
Object.freeze(myCustomObj); |
This file contains hidden or 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 utils = { | |
deepFreeze: obj => { | |
Object.freeze(obj); | |
Object.getOwnPropertyNames(obj).forEach(prop => { | |
const isNotNullOrUndefined = () => | |
obj[prop] !== null || typeof obj[prop] !== "undefined"; | |
const hasOwnProperty = () => obj.hasOwnProperty(prop); |
This file contains hidden or 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
/* ---- DONT DO IT ----- */ | |
const globalOrWindow = typeof global !== "undefined" ? global : window; //checks if the environment is node or browser | |
globalOrWindow.params = { | |
device: "iPhone", | |
useGPS: false, | |
useAcelerometer: true, | |
deviceUniqueID: Math.floor(Math.random() * 300), | |
}; |