Skip to content

Commit

Permalink
docs: update docs deps and add new docs
Browse files Browse the repository at this point in the history
  • Loading branch information
nartc committed Apr 7, 2021
1 parent e2c1d99 commit 16719ff
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 190 deletions.
12 changes: 6 additions & 6 deletions docs-site/docs/getting-started/introduce-to-automapper.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,12 @@ export class User {

password: string;

@AutoMap(() => Bio)
@AutoMap({ typeFn: () => Bio })
bio: Bio;
}

export class Bio {
@AutoMap(() => Job)
@AutoMap({ typeFn: () => Job })
job: Job;

birthday: Date;
Expand Down Expand Up @@ -176,7 +176,7 @@ export class UserDto {
@AutoMap()
username: string;

@AutoMap(() => BioDto)
@AutoMap({ typeFn: () => BioDto })
bio: BioDto;
}

Expand Down Expand Up @@ -379,12 +379,12 @@ export class User {

password: string;

@AutoMap(() => Bio)
@AutoMap({ typeFn: () => Bio })
bio: Bio;
}

export class Bio {
@AutoMap(() => Job)
@AutoMap({ typeFn: () => Job })
job: Job;

birthday: Date;
Expand Down Expand Up @@ -413,7 +413,7 @@ export class UserDto {
@AutoMap()
username: string;

@AutoMap(() => BioDto)
@AutoMap({ typeFn: () => BioDto })
bio: BioDto;
}

Expand Down
8 changes: 4 additions & 4 deletions docs-site/docs/mapping-configuration/auto.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Bar {
class Foo {
@AutoMap()
foo: string;
@AutoMap(() => Bar)
@AutoMap({ typeFn: () => Bar })
bar: Bar;
}

Expand Down Expand Up @@ -112,7 +112,7 @@ export class Address {
}

export class User {
@AutoMap(() => Address)
@AutoMap({ typeFn: () => Address })
addresses: Address[];
}

Expand All @@ -122,7 +122,7 @@ export class AddressDto {
}

export class UserDto {
@AutoMap(() => AddressDto)
@AutoMap({ typeFn: () => AddressDto })
addresses: AddressDto[];
}
```
Expand Down Expand Up @@ -153,7 +153,7 @@ export enum UserRole {
}

export class User {
@AutoMap(() => String) // because UserRole is a string enum
@AutoMap({ typeFn: () => String }) // because UserRole is a string enum
role: UserRole;
}

Expand Down
18 changes: 18 additions & 0 deletions docs-site/docs/mapping-configuration/map-with-arguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,22 @@ const dto = mapper.map(someUser, UserDto, User, {
});
```

## Value Resolver

[Resolver](./map-from.md) can also be used with `mapWithArguments`

```ts
export const taxResolver: Resolver<Item, { percentage: number }, number> = {
resolve(source, { percentage }) {
return source.price * percentage;
},
};

mapper
.createMap(Item, ItemDto)
.forMember((destination) => destination.tax, mapWithArguments(taxResolver));

mapper.map(item, ItemDto, Item, { extraArguments: { percentage: 0.5 } };
```
`mapWithArguments()` will set the `TransformationType` to `TransformationType.MapWithArguments`
4 changes: 2 additions & 2 deletions docs-site/docs/migrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,11 @@ In `@automapper/core`, `ErrorHandler#handle` is default to `console.error`. `ski

```ts
// string enum
@AutoMap(() => String)
@AutoMap({ typeFn: () => String })
role: UserRole

// number enum
@AutoMap(() => Number)
@AutoMap({ typeFn: () => Number })
role: UserRole
```

Expand Down
22 changes: 11 additions & 11 deletions docs-site/docs/plugins-system/classes-limitations.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ When designing your data models, both Domain and DTO (or View Model), you will p
class SourceA {
@AutoMap()
id: number;
@AutoMap(() => SourceB)
@AutoMap({ typeFn: () => SourceB })
sourceB: SourceB;
}

class SourceB {
@AutoMap()
id: number;
@AutoMap(() => SourceA)
@AutoMap({ typeFn: () => SourceA })
sourceA: SourceA;
}
```
Expand All @@ -38,7 +38,7 @@ export class Order {
id: number;
// ... shorten for brevity purpose
@ManyToOne(() => Person, (person) => person.orders)
@AutoMap(() => Person)
@AutoMap({ typeFn: () => Person })
person: Person;
}

Expand All @@ -48,7 +48,7 @@ export class Person {
id: number;
// ... shorten for brevity purpose
@OneToMany(() => Order, (order) => order.person)
@AutoMap(() => Order)
@AutoMap({ typeFn: () => Order })
orders: Order[];
}
```
Expand All @@ -63,14 +63,14 @@ In general, you should avoid introducing **Circular Dependency** as much as poss
class SourceA {
@AutoMap()
id: number;
@AutoMap(() => SourceB)
@AutoMap({ typeFn: () => SourceB })
sourceB: SourceB;
}

class SourceB {
@AutoMap()
id: number;
@AutoMap(() => SourceA)
@AutoMap({ typeFn: () => SourceA })
sourceA: SourceA;
}
```
Expand Down Expand Up @@ -121,14 +121,14 @@ By default, `@automapper/classes` will apply **depth of 0** to nested models. To
class SourceA {
@AutoMap()
id: number;
@AutoMap(() => SourceB, 1)
@AutoMap({ typeFn: () => SourceB, depth: 1 })
sourceB: SourceB;
}

class SourceB {
@AutoMap()
id: number;
@AutoMap(() => SourceA, 1)
@AutoMap({ typeFn: () => SourceA, depth: 1 })
sourceA: SourceA;
}
```
Expand Down Expand Up @@ -180,11 +180,11 @@ If you have `strict` mode turned on, and you have **Union Type** on your propert

```ts
export class User {
@AutoMap(() => String)
@AutoMap({ typeFn: () => String })
name!: string | null;
@AutoMap(() => Number)
@AutoMap({ typeFn: () => Number })
age!: number | null;
@AutoMap(() => Boolean)
@AutoMap({ typeFn: () => Boolean })
isAdmin!: boolean | null;
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class User {
firstName: string;
@AutoMap()
lastName: string;
@AutoMap(() => Profile)
@AutoMap({ typeFn: () => Profile })
profile: Profile;
}
```
Expand Down
8 changes: 4 additions & 4 deletions docs-site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
"postinstall": "yarn build"
},
"dependencies": {
"@docusaurus/core": "2.0.0-alpha.71",
"@docusaurus/preset-classic": "2.0.0-alpha.71",
"@docusaurus/core": "2.0.0-alpha.72",
"@docusaurus/preset-classic": "2.0.0-alpha.72",
"@mdx-js/react": "1.6.22",
"clsx": "1.1.1",
"react": "17.0.1",
"react-dom": "17.0.1"
"react": "17.0.2",
"react-dom": "17.0.2"
},
"browserslist": {
"production": [
Expand Down
Loading

0 comments on commit 16719ff

Please sign in to comment.