@effect/data
Advanced tools
Comparing version 0.4.0 to 0.4.1
@@ -78,5 +78,5 @@ /** | ||
*/ | ||
export declare const TaggedClass: <Key extends string>(tag: Key) => <A extends Record<string, any>>() => new (args: Omit<A, keyof Equal.Equal | "_tag">) => Readonly<A> & Equal.Equal & { | ||
readonly _tag: Key; | ||
}; | ||
export declare const TaggedClass: <Key extends string>(tag: Key) => <A extends Record<string, any>>() => new (args: Omit<A, keyof Equal.Equal>) => Data<A & { | ||
_tag: Key; | ||
}>; | ||
/** | ||
@@ -83,0 +83,0 @@ * Provides a constructor for a Case Class. |
24
Data.js
@@ -105,7 +105,6 @@ "use strict"; | ||
const TaggedClass = tag => () => { | ||
class Base { | ||
constructor(args) { | ||
class Base extends Class() { | ||
constructor() { | ||
super(...arguments); | ||
this._tag = tag; | ||
Object.assign(this, args); | ||
unsafeStruct(this); | ||
} | ||
@@ -126,4 +125,19 @@ } | ||
Object.assign(this, args); | ||
unsafeStruct(this); | ||
} | ||
[Hash.symbol]() { | ||
return Hash.structure(this); | ||
} | ||
[Equal.symbol](that) { | ||
const selfKeys = Object.keys(this); | ||
const thatKeys = Object.keys(that); | ||
if (selfKeys.length !== thatKeys.length) { | ||
return false; | ||
} | ||
for (const key of selfKeys) { | ||
if (!(key in that && Equal.equals(this[key], that[key]))) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
} | ||
@@ -130,0 +144,0 @@ return Base; |
{ | ||
"name": "@effect/data", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -139,11 +139,7 @@ /** | ||
) => | ||
<A extends Record<string, any>>() => { | ||
class Base { | ||
<A extends Record<string, any>>(): new(args: Omit<A, keyof Equal.Equal>) => Data<A & { _tag: Key }> => { | ||
class Base extends (Class<A>() as any) { | ||
readonly _tag = tag | ||
constructor(args: Omit<A, "_tag" | keyof Equal.Equal>) { | ||
Object.assign(this, args) | ||
unsafeStruct(this) | ||
} | ||
} | ||
return Base as unknown as { new(args: Omit<A, "_tag" | keyof Equal.Equal>): Data<A> & { readonly _tag: Key } } | ||
return Base as any | ||
} | ||
@@ -157,10 +153,26 @@ | ||
*/ | ||
export const Class = <A extends Record<string, any>>() => { | ||
export const Class = <A extends Record<string, any>>(): new(args: Omit<A, keyof Equal.Equal>) => Data<A> => { | ||
class Base { | ||
constructor(args: Omit<A, keyof Equal.Equal>) { | ||
Object.assign(this, args) | ||
unsafeStruct(this) | ||
} | ||
[Hash.symbol](this: Equal.Equal) { | ||
return Hash.structure(this) | ||
} | ||
[Equal.symbol](this: Equal.Equal, that: Equal.Equal) { | ||
const selfKeys = Object.keys(this) | ||
const thatKeys = Object.keys(that as object) | ||
if (selfKeys.length !== thatKeys.length) { | ||
return false | ||
} | ||
for (const key of selfKeys) { | ||
if (!(key in (that as object) && Equal.equals(this[key], (that as object)[key]))) { | ||
return false | ||
} | ||
} | ||
return true | ||
} | ||
} | ||
return Base as unknown as { new(args: Omit<A, keyof Equal.Equal>): Data<A> } | ||
return Base as any | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3483138
74152