Skip to content

Commit

Permalink
added var params for aggregates
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-jonathan committed Jan 2, 2024
1 parent 29da0f4 commit b8629c7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cosmicmind/domainjs",
"version": "0.0.1-rc-010124-4-b",
"version": "0.0.1-rc-010124-4-c",
"description": "A domain-driven design framework for scalable systems.",
"keywords": [],
"author": {
Expand Down
8 changes: 4 additions & 4 deletions src/Aggregate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ import {
export abstract class Aggregate<E extends Entity, T extends EventTopics = EventTopics> extends EventObservable<T> {
protected root: E

protected constructor(root: E) {
constructor(root: E) {
super()
this.root = root
}
}

export type AggregateTypeFor<A> = A extends Aggregate<infer E> ? E : A

export type AggregateConstructor<A extends Aggregate<Entity>> = new (root: AggregateTypeFor<A>) => A
export type AggregateConstructor<A extends Aggregate<Entity>> = new (root: AggregateTypeFor<A>, ...args: unknown[]) => A

export function defineAggregate<A extends Aggregate<Entity>>(_class: AggregateConstructor<A>, handler: EntityLifecycle<AggregateTypeFor<A>> = {}): (root: AggregateTypeFor<A>) => A {
export function defineAggregate<A extends Aggregate<Entity>>(_class: AggregateConstructor<A>, handler: EntityLifecycle<AggregateTypeFor<A>> = {}): (root: AggregateTypeFor<A>, ...args: unknown[]) => A {
const createEntity = defineEntity<AggregateTypeFor<A>>(handler)
return (root: AggregateTypeFor<A>): A => new _class(createEntity(root))
return (root: AggregateTypeFor<A>, ...args: unknown[]): A => new _class(createEntity(root), ...args)
}

0 comments on commit b8629c7

Please sign in to comment.