Skip to content

Commit

Permalink
improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
bennett-sh committed May 8, 2023
1 parent 7ac46d1 commit 73e85b3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
4 changes: 2 additions & 2 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ repo
```

### Mass Patches
One of the largest advantages of Repository Script is the ability to mass patch items. To do so, use the functions ```Repository::patchAll``` and/or ```Repository::patchAllAsync```.
One of the largest advantages of Repository Script is the ability to mass patch items. To do so, use the functions ```Repository::patchAll```, ```Repository::patchAllFn``` and ```Repository::patchAllAsync```.
```ts
repo.patchAll(RepositoryGroups.Pistols, {
TestProp: 'asd'
})
repo.patchAll(RepositoryGroups.Explosives, item => ({
repo.patchAllFn(RepositoryGroups.Explosives, item => ({
TestProp: item.id
}))
await repo.patchAllAsync(RepositoryGroups.Tools, async (item) => ({
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "repository-script",
"version": "1.0.7",
"version": "1.0.8",
"description": "An easier way of writing repository files with code",
"main": "dist/src/lib.js",
"types": "./dist/src/index.d.ts",
Expand Down
14 changes: 6 additions & 8 deletions src/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,15 @@ export class Repository {
return this
}

public patchAll(ids: TUUIDv4[], handler: (entry: RepositoryEntry) => void): this
public patchAll(ids: TUUIDv4[], handler: Partial<IRepositoryItem>): this
public patchAll(ids, handler): this {
public patchAll(ids: TUUIDv4[], data: Partial<IRepositoryItem>): this {
ids.forEach(id => this.patch(id, data))
return this
}

public patchAllFn(ids: TUUIDv4[], handler: (entry: RepositoryEntry) => Partial<IRepositoryItem>): this {
ids.forEach(id => {
const entry = this.getItem(id)

if(!(handler instanceof Function)) {
entry.patch(handler)
return
}

entry.patch(handler(entry))
})
return this
Expand Down

0 comments on commit 73e85b3

Please sign in to comment.