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
| import { | |
| Injectable, | |
| Injector, | |
| ComponentFactoryResolver, | |
| EmbeddedViewRef, | |
| ApplicationRef | |
| } from '@angular/core'; | |
| @Injectable() | |
| export class DomService { |
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 promise1 = new Promise((resolve, reject) => resolve("Resolved promise1!")); | |
| const promise2 = new Promise((resolve, reject) => reject("Rejected promise2!")); | |
| const promise3 = new Promise((resolve, reject) => resolve("Resolved promise3!")); | |
| const allPromises = [promise1, promise2, promise3]; | |
| Promise.all(allPromises).then((results) => { | |
| //if all promises in the collection resolves, `results` is an array of [promise1 result, promise2 result, promise3 result] | |
| }).catch((error) => { | |
| //if any promise is rejected, `error` will have the rejected value of the promise that failed | |
| //if multiple failed, `error` will be the error of the first one that failed |
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 renamed = ({ ID, ...object }) => ({ id: ID, ...object }) | |
| const user = { | |
| ID: 500, | |
| name: "Bob Fossil" | |
| } | |
| renamed(user) //=> { id: 500, name: 'Bob Fossil' } |
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 user = { id: 100, name: 'Howard Moon' } | |
| const password = 'Password!' | |
| const userWithPassword = { | |
| ...user, | |
| id: 100, | |
| ...(password && { password }) | |
| } | |
| userWithPassword //=> { id: 100, name: 'Howard Moon', password: 'Password!' } |
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 setDefaults = ({ ...object}) => ({ quotes: [], ...object }) |
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 user1 = { | |
| id: 100, | |
| name: 'Howard Moon', | |
| password: 'Password!' | |
| } | |
| const removeProperty = prop => ({ [prop]: _, ...rest }) => rest | |
| // ---- ------ | |
| // \ / | |
| // dynamic destructuring |
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 partial = { id: 100, name: 'Howard Moon' } | |
| const user = { ...partial, id: 100, password: 'Password!' } | |
| user //=> { id: 100, name: 'Howard Moon', password: 'Password!' } |
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 noPassword = ({ password, ...rest }) => rest | |
| const user = { | |
| id: 100, | |
| name: 'Howard Moon', | |
| password: 'Password!' | |
| } | |
| noPassword(user) //=> { id: 100, name: 'Howard moon' } |
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 part1 = { id: 100, name: 'Howard Moon' } | |
| const part2 = { id: 100, password: 'Password!' } | |
| const user1 = { ...part1, ...part2 } | |
| //=> { id: 100, name: 'Howard Moon', password: 'Password!' } |