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 UNGROUPED_KEY = 'ungrouped'; | |
const transformCollection = (collection, keyField) => collection.reduce((acc, curValue) => { | |
const DESIRED_KEY = curValue[keyField]; | |
if (acc[`${DESIRED_KEY}`.toLowerCase()]) { | |
acc[`${DESIRED_KEY}`.toLowerCase()] = [...acc[`${DESIRED_KEY}`.toLowerCase()], curValue]; | |
} else { | |
if (DESIRED_KEY) { | |
acc[`${DESIRED_KEY}`.toLowerCase()] = [curValue]; | |
} else { |
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
class Gestures { | |
constructor(output) { | |
this.name = 'Gestures'; | |
this.output = output; | |
} | |
tap() { | |
return this.output.click(this.name); | |
} |
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
class Flyweight { | |
constructor(state) { | |
this.state = state; | |
} | |
} | |
class FlyWeightFactory { | |
constructor(flyweightsList) { | |
this.flyweights = {}; | |
flyweightsList.forEach((item) => { |
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
class ServiceInteraction { | |
constructor(url) { | |
this.url = url; | |
} | |
sendRequest(path, method) { | |
return fetch(`https://${this.url}/${path}`, { | |
method, | |
}) | |
.then((res) => res.json()) |
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
class WebsocketInteraction { | |
constructor(url, port) { | |
this.url = url; | |
this.port = port; | |
} | |
connect() { | |
return new Promise((resolve) => { | |
this.connection = new WebSocket(`wss://${this.url}:${this.port}`); | |
this.connection.onopen = (e) => { |
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
class ServiceInteraction { | |
constructor(url, port) { | |
this.url = url; | |
this.port = port; | |
} | |
connect() { | |
return new Promise((resolve) => { | |
this.connection = new WebSocket(`wss://${this.url}:${this.port}`); | |
this.connection.onopen = (e) => { |
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
class Composite { | |
constructor(compositeName) { | |
this.children = []; | |
this.compositeName = compositeName; | |
} | |
add(child) { | |
this.children.push(child); | |
} |
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
class OldDateConverter { | |
convertToUSAFormat(dateObject) { | |
const [y, m, d] = dateObject.toISOString().substr(0, 10).split('-'); | |
return [m, d, y].join('-'); | |
} | |
convertToRussianFormat(dateObject) { | |
const [y, m, d] = dateObject.toISOString().substr(0, 10).split('-'); | |
return [d, m, y].join('-'); | |
} |
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
class Singleton { | |
constructor(data) { | |
if (Singleton.instance) { | |
return Singleton.instance; | |
} | |
Singleton.instance = this; | |
this.data = data; | |
return this; |
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
class Prototype { | |
setOption(key, val) { | |
this[key] = val; | |
} | |
clone() { | |
const clone = new Prototype(); | |
const keys = Object.keys(this); | |
keys.forEach((k) => clone.setOption(k, this[k])); |
NewerOlder