-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add conceptFrom functions for ConceptAs and deprecate static from methods #11
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, I added some tests for it too (and had to try it out myself 😋).
export function conceptFromFor<C extends ConceptAs<T, U>, T extends ConceptBase, U extends string>(conceptConstructor: Constructor<ConceptAs<T, U>>): (concept: T) => C { | ||
return (concept: T) => conceptFrom(conceptConstructor, concept) as C; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a fat comment here about how to use this extra fancy conceptFromFor()()
thingy but I accidentally closed the tab so in short:
Is there a reason you'd ever want to use the ()()
fancyness over the clear conceptFrom(SomeId, id)
method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like you can add a static method like this to your concept class:
class SomeId ...{
/// ... class stuff ...
static from: (concept: SomeId) {
return conceptFromFor(SomeId);
}
}
const someId = SomeId.from(Guid.create());
Or you could make reference on spot:
const toSomeId = conceptFromFor(SomeId);
const someId = toSomeId(Guid.create());
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this was the scenarios I had in mind. Since we don't have a way to inherit this static method in a good way
Can use the functions like this: