HOWPROGRAMMINGWORKS Telegram 1822
πŸ‘©β€πŸ’» Π­Ρ‚ΠΎ Ρ€Π΅ΡˆΠ΅Π½ΠΈΠ΅Π²ΠΌΠ΅ΡΡ‚ΠΎ нСпринятого TC39 ΠΈΠΌΠΌΡƒΡ‚Π°Π±Π΅Π»ΡŒΠ½ΠΎΠ³ΠΎ ΠΎΠ±ΡŠΠ΅ΠΊΡ‚Π°
- ΠΈΠΌΠΌΡƒΡ‚Π°Π±Π΅Π»ΡŒΠ½Ρ‹Π΅ ΠΌ ΠΌΡƒΡ‚Π°Π±Π΅Π»ΡŒΠ½Ρ‹Π΅ записи (ΠΎΠ±ΡŠΠ΅ΠΊΡ‚Ρ‹) с ΠΎΠΏΡ‚ΠΈΠΌΠΈΠ·Π°Ρ†ΠΈΠ΅ΠΉ Ρ„ΠΎΡ€ΠΌΡ‹
- ΠΏΠΎΠ»Π½ΠΎΠ΅ ΠΊΠ»ΠΎΠ½ΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅, модификация, ΠΊΠ»ΠΎΠ½ΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅ с ΠΏΡ€ΠΎΡ‚ΠΎΡ‚ΠΈΠΏΠ½Ρ‹ΠΌ наслСдованиСм
- ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΠ° Ρ‚ΠΈΠΏΠΎΠ² Π² Ρ€Π°Π½Ρ‚Π°ΠΉΠΌΠ΅, Π΄Π΅Ρ„ΠΎΠ»Ρ‚Π½Ρ‹Π΅ значСния ΠΏΠΎΠ»Π΅ΠΉ
- ΠΈΠΌΠΌΡƒΡ‚Π°Π±Π΅Π»ΡŒΠ½Ρ‹Π΅ записи с экономиСй памяти Π·Π° счСт Ρ†Π΅ΠΏΠΎΡ‡Π΅ΠΊ ΠΏΡ€ΠΎΡ‚ΠΎΡ‚ΠΈΠΏΠΎΠ²
- ускорСниС поиска ΠΏΠΎΠ»Π΅ΠΉ ΠΈ ΠΎΠΏΡ‚ΠΈΠΌΠΈΠ·Π°Ρ†ΠΈΠΈ для V8, Π΄Π°ΠΆΠ΅ Π² сравнСнии с Π»ΠΈΡ‚Π΅Ρ€Π°Π»ΠΎΠΌ ΠΎΠ±ΡŠΠ΅ΠΊΡ‚Π°
Π’ΡƒΡ‚ Π΅Ρ‰Π΅ Π½ΡƒΠΆΠ½ΠΎ ΠΌΠ½ΠΎΠ³ΠΎΠ΅ ΠΎΠΏΡ‚ΠΈΠΌΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ, Π½ΠΎ ΠΏΠΎΠ»Π½ΠΎΠ΅ Ρ€Π΅ΡˆΠ΅Π½ΠΈΠ΅ Π±ΡƒΠ΄Π΅Ρ‚ Ρ‚ΡƒΡ‚: https://github.com/metarhia/metautil/pull/298
class Record {
static immutable(defaults) {
return Record.#build(defaults, false);
}

static mutable(defaults) {
return Record.#build(defaults, true);
}

static #build(defaults, isMutable) {
const fields = Object.keys(defaults);
const defaultValues = Object.create(null);
for (const key of fields) {
defaultValues[key] = defaults[key];
}

class Struct {
static fields = fields;
static defaults = defaultValues;
static mutable = isMutable;

static create(data = {}) {
const obj = Object.create(null);
for (const key of fields) {
const base = defaultValues[key];
const value = key in data ? data[key] : base;
if (!Record.#sameType(base, value)) {
const exp = Record.#typeof(base);
const act = Record.#typeof(value);
throw new TypeError(
`Invalid type for "${key}": expected ${exp}, got ${act}`,
);
}
obj[key] = value;
}
return isMutable ? Object.seal(obj) : Object.freeze(obj);
}
}
return Struct;
}

static #typeof(value) {
if (Array.isArray(value)) return 'array';
if (value === null) return 'null';
return typeof value;
}

static #sameType(a, b) {
if (Array.isArray(a)) return Array.isArray(b);
if (a === null) return b === null;
return typeof a === typeof b;
}

static #validate(instance, updates) {
for (const key of Object.keys(updates)) {
if (!Reflect.has(instance, key)) continue;
const current = instance[key];
const next = updates[key];
if (!Record.#sameType(current, next)) {
const exp = Record.#typeof(current);
const act = Record.#typeof(next);
throw new TypeError(
`Invalid type for "${key}": expected ${exp}, got ${act}`,
);
}
}
}

static update(instance, updates) {
if (Object.isFrozen(instance)) {
throw new Error('Cannot mutate immutable Record');
}
Record.#validate(instance, updates);
for (const key of Object.keys(updates)) {
if (Reflect.has(instance, key)) {
instance[key] = updates[key];
}
}
return instance;
}

static fork(instance, updates) {
Record.#validate(instance, updates);
const obj = Object.create(null);
for (const key of Object.keys(instance)) {
obj[key] = Reflect.has(updates, key) ? updates[key] : instance[key];
}
return Object.isFrozen(instance) ? Object.freeze(obj) : Object.seal(obj);
}

static branch(instance, updates) {
Record.#validate(instance, updates);
const obj = Object.create(instance);
for (const key of Object.keys(updates)) {
Reflect.defineProperty(obj, key, {
value: updates[key],
writable: true,
configurable: true,
enumerable: true,
});
}
return Object.isFrozen(instance) ? Object.freeze(obj) : Object.seal(obj);
}
}
Please open Telegram to view this post
VIEW IN TELEGRAM



tgoop.com/HowProgrammingWorks/1822
Create:
Last Update:

πŸ‘©β€πŸ’» Π­Ρ‚ΠΎ Ρ€Π΅ΡˆΠ΅Π½ΠΈΠ΅Π²ΠΌΠ΅ΡΡ‚ΠΎ нСпринятого TC39 ΠΈΠΌΠΌΡƒΡ‚Π°Π±Π΅Π»ΡŒΠ½ΠΎΠ³ΠΎ ΠΎΠ±ΡŠΠ΅ΠΊΡ‚Π°
- ΠΈΠΌΠΌΡƒΡ‚Π°Π±Π΅Π»ΡŒΠ½Ρ‹Π΅ ΠΌ ΠΌΡƒΡ‚Π°Π±Π΅Π»ΡŒΠ½Ρ‹Π΅ записи (ΠΎΠ±ΡŠΠ΅ΠΊΡ‚Ρ‹) с ΠΎΠΏΡ‚ΠΈΠΌΠΈΠ·Π°Ρ†ΠΈΠ΅ΠΉ Ρ„ΠΎΡ€ΠΌΡ‹
- ΠΏΠΎΠ»Π½ΠΎΠ΅ ΠΊΠ»ΠΎΠ½ΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅, модификация, ΠΊΠ»ΠΎΠ½ΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅ с ΠΏΡ€ΠΎΡ‚ΠΎΡ‚ΠΈΠΏΠ½Ρ‹ΠΌ наслСдованиСм
- ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΠ° Ρ‚ΠΈΠΏΠΎΠ² Π² Ρ€Π°Π½Ρ‚Π°ΠΉΠΌΠ΅, Π΄Π΅Ρ„ΠΎΠ»Ρ‚Π½Ρ‹Π΅ значСния ΠΏΠΎΠ»Π΅ΠΉ
- ΠΈΠΌΠΌΡƒΡ‚Π°Π±Π΅Π»ΡŒΠ½Ρ‹Π΅ записи с экономиСй памяти Π·Π° счСт Ρ†Π΅ΠΏΠΎΡ‡Π΅ΠΊ ΠΏΡ€ΠΎΡ‚ΠΎΡ‚ΠΈΠΏΠΎΠ²
- ускорСниС поиска ΠΏΠΎΠ»Π΅ΠΉ ΠΈ ΠΎΠΏΡ‚ΠΈΠΌΠΈΠ·Π°Ρ†ΠΈΠΈ для V8, Π΄Π°ΠΆΠ΅ Π² сравнСнии с Π»ΠΈΡ‚Π΅Ρ€Π°Π»ΠΎΠΌ ΠΎΠ±ΡŠΠ΅ΠΊΡ‚Π°
Π’ΡƒΡ‚ Π΅Ρ‰Π΅ Π½ΡƒΠΆΠ½ΠΎ ΠΌΠ½ΠΎΠ³ΠΎΠ΅ ΠΎΠΏΡ‚ΠΈΠΌΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ, Π½ΠΎ ΠΏΠΎΠ»Π½ΠΎΠ΅ Ρ€Π΅ΡˆΠ΅Π½ΠΈΠ΅ Π±ΡƒΠ΄Π΅Ρ‚ Ρ‚ΡƒΡ‚: https://github.com/metarhia/metautil/pull/298

class Record {
static immutable(defaults) {
return Record.#build(defaults, false);
}

static mutable(defaults) {
return Record.#build(defaults, true);
}

static #build(defaults, isMutable) {
const fields = Object.keys(defaults);
const defaultValues = Object.create(null);
for (const key of fields) {
defaultValues[key] = defaults[key];
}

class Struct {
static fields = fields;
static defaults = defaultValues;
static mutable = isMutable;

static create(data = {}) {
const obj = Object.create(null);
for (const key of fields) {
const base = defaultValues[key];
const value = key in data ? data[key] : base;
if (!Record.#sameType(base, value)) {
const exp = Record.#typeof(base);
const act = Record.#typeof(value);
throw new TypeError(
`Invalid type for "${key}": expected ${exp}, got ${act}`,
);
}
obj[key] = value;
}
return isMutable ? Object.seal(obj) : Object.freeze(obj);
}
}
return Struct;
}

static #typeof(value) {
if (Array.isArray(value)) return 'array';
if (value === null) return 'null';
return typeof value;
}

static #sameType(a, b) {
if (Array.isArray(a)) return Array.isArray(b);
if (a === null) return b === null;
return typeof a === typeof b;
}

static #validate(instance, updates) {
for (const key of Object.keys(updates)) {
if (!Reflect.has(instance, key)) continue;
const current = instance[key];
const next = updates[key];
if (!Record.#sameType(current, next)) {
const exp = Record.#typeof(current);
const act = Record.#typeof(next);
throw new TypeError(
`Invalid type for "${key}": expected ${exp}, got ${act}`,
);
}
}
}

static update(instance, updates) {
if (Object.isFrozen(instance)) {
throw new Error('Cannot mutate immutable Record');
}
Record.#validate(instance, updates);
for (const key of Object.keys(updates)) {
if (Reflect.has(instance, key)) {
instance[key] = updates[key];
}
}
return instance;
}

static fork(instance, updates) {
Record.#validate(instance, updates);
const obj = Object.create(null);
for (const key of Object.keys(instance)) {
obj[key] = Reflect.has(updates, key) ? updates[key] : instance[key];
}
return Object.isFrozen(instance) ? Object.freeze(obj) : Object.seal(obj);
}

static branch(instance, updates) {
Record.#validate(instance, updates);
const obj = Object.create(instance);
for (const key of Object.keys(updates)) {
Reflect.defineProperty(obj, key, {
value: updates[key],
writable: true,
configurable: true,
enumerable: true,
});
}
return Object.isFrozen(instance) ? Object.freeze(obj) : Object.seal(obj);
}
}

BY HowProgrammingWorks - JavaScript and Node.js Programming


Share with your friend now:
tgoop.com/HowProgrammingWorks/1822

View MORE
Open in Telegram


Telegram News

Date: |

Some Telegram Channels content management tips The main design elements of your Telegram channel include a name, bio (brief description), and avatar. Your bio should be: While the character limit is 255, try to fit into 200 characters. This way, users will be able to take in your text fast and efficiently. Reveal the essence of your channel and provide contact information. For example, you can add a bot name, link to your pricing plans, etc. How to create a business channel on Telegram? (Tutorial) The initiatives announced by Perekopsky include monitoring the content in groups. According to the executive, posts identified as lacking context or as containing false information will be flagged as a potential source of disinformation. The content is then forwarded to Telegram's fact-checking channels for analysis and subsequent publication of verified information.
from us


Telegram HowProgrammingWorks - JavaScript and Node.js Programming
FROM American