Skip to content

Commit

Permalink
allow passing raw query string to plexus api
Browse files Browse the repository at this point in the history
  • Loading branch information
itsRems committed Sep 5, 2024
1 parent 40abbbd commit 9f5403d
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 30 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ __snapshots__
*.tsbuildinfo
*.tgz
*.log
.DS_Store
Binary file modified bun.lockb
Binary file not shown.
26 changes: 13 additions & 13 deletions docs/docs/api-reference/batch.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,29 @@ Run a function. During that function's execution, any state changes will be batc
| ----- | ------------------------------------- |
| fn | <p>The function to run in a batch</p> |

<a name='RuntimeInstance+batch'></a>
<a name='Scope+batch'></a>

## .batch(fn)

<p>
The batch function allows you to run a series of reactive actions in a single
transaction. If there is already a batch in progress, the function will be
added to the batch and run when the batch is released.
Run a function. During that function's execution, any state changes will be
batched and only applied once the function has finished.
</p>

| Param | Type | Description |
| ----- | --------------------- | -------------------------- |
| fn | <code>function</code> | <p>The function to run</p> |
| Param | Description |
| ----- | ------------------------------------- |
| fn | <p>The function to run in a batch</p> |

<a name='Scope+batch'></a>
<a name='RuntimeInstance+batch'></a>

## .batch(fn)

<p>
Run a function. During that function's execution, any state changes will be
batched and only applied once the function has finished.
The batch function allows you to run a series of reactive actions in a single
transaction. If there is already a batch in progress, the function will be
added to the batch and run when the batch is released.
</p>

| Param | Description |
| ----- | ------------------------------------- |
| fn | <p>The function to run in a batch</p> |
| Param | Type | Description |
| ----- | --------------------- | -------------------------- |
| fn | <code>function</code> | <p>The function to run</p> |
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,6 @@
},
"publishConfig": {
"registry": "https://npm.pkg.github.com"
}
},
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
26 changes: 15 additions & 11 deletions packages/plexus-api/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,18 +291,22 @@ export class ApiInstance {
*/
get<ResponseType = any>(
path: string,
query?: Record<string, any>,
query?: Record<string, any> | string,
options?: PlexusApiFetchOptions
) {
const params = new URLSearchParams(query)
let params = query ? new URLSearchParams(query).toString() : ''
if (typeof query === 'string') {
params = query
}

return this.send<ResponseType>(
`${path}${params.toString().length > 0 ? `?${params.toString()}` : ''}`,
{
...options,
method: 'GET',
}
)
if (!params.startsWith('?') && params.length > 0) {
params = `?${params}`
}

return this.send<ResponseType>(`${path}${params}`, {
...options,
method: 'GET',
})
}

/**
Expand All @@ -313,7 +317,7 @@ export class ApiInstance {
*/
async post<
ResponseType = any,
BodyType extends Record<string, any> | string = {}
BodyType extends Record<string, any> | string = {},
>(
path: string,
body: BodyType = {} as BodyType,
Expand Down Expand Up @@ -466,7 +470,7 @@ export class ApiInstance {
setHeaders<
HeaderFunction extends () =>
| Record<string, any>
| Promise<Record<string, any>>
| Promise<Record<string, any>>,
>(inputFnOrObj: HeaderFunction | Record<string, any>) {
// if (!_headers) _internalStore._options.headers = {}
if (this._internalStore.noFetch) return this
Expand Down
2 changes: 1 addition & 1 deletion tests/edgecases.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe('Collection Relations', () => {
)

test('Batching race condition with selectors', () => {
batch(() => { })
batch(() => {})
})
})

Expand Down
Loading

0 comments on commit 9f5403d

Please sign in to comment.