-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from eloqjs/dev
Release v1.0.0-alpha.7
- Loading branch information
Showing
30 changed files
with
10,490 additions
and
207 deletions.
There are no files selected for viewing
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
tasks: | ||
- init: yarn install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"plugins": [ | ||
"@semantic-release/commit-analyzer", | ||
["@semantic-release/release-notes-generator", { | ||
"writerOpts": { | ||
"headerPartial": ".github/templates/release-notes-generator/header.hbs" | ||
} | ||
}], | ||
"@semantic-release/npm", | ||
"@semantic-release/github" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules | ||
.nuxt | ||
dist | ||
static/sw.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
--- | ||
title: Configuration | ||
description: You can configure @eloqjs/collection with the Collection.config property in src/main.js. | ||
category: Getting Started | ||
position: 3 | ||
--- | ||
|
||
<alert type="warning">This documentation still in development.</alert> | ||
|
||
<alert type="info">If you are using **Nuxt** or **Vue**, please follow their configuration steps instead of this one.</alert> | ||
|
||
You can configure `@eloqjs/collection` with the `Collection.config` property in `src/main.js`. | ||
|
||
```js{}[src/main.js] | ||
import { Collection } from '@eloqjs/collection' | ||
Collection.config = { | ||
// My custom configuration | ||
} | ||
``` | ||
|
||
## Frameworks | ||
|
||
### Nuxt | ||
|
||
You can configure `@eloqjs/nuxt-collection` with the `collection` property in your `nuxt.config.js`. | ||
|
||
```js{}[nuxt.config.js] | ||
export default { | ||
collection: { | ||
// My custom configuration | ||
} | ||
} | ||
``` | ||
|
||
### Vue | ||
|
||
You can configure `@eloqjs/vue-collection` by passing the options to `Vue.use` in `src/main.js`. | ||
|
||
```js{}[src/main.js] | ||
import vue from 'vue' | ||
import Collection from '@eloqjs/vue-collection' | ||
Vue.use(Collection, { | ||
// My custom configuration | ||
}) | ||
``` | ||
|
||
|
||
## Properties | ||
|
||
### `primaryKey` | ||
|
||
- Type: `() => string` | ||
- Arguments: `({ collection })` | ||
- Default: `id` | ||
|
||
The primary key of the items. | ||
|
||
<code-group> | ||
<code-block label="JavaScript" active> | ||
|
||
```js | ||
{ | ||
primaryKey: ({ collection }) => { | ||
const item = collection.first() | ||
|
||
if (item.type === 'article') { | ||
return 'slug' | ||
} | ||
|
||
return 'id' | ||
} | ||
} | ||
``` | ||
|
||
</code-block> | ||
<code-block label="TypeScript"> | ||
|
||
```ts | ||
import { Collection, ItemData } from '@eloqjs/collection' | ||
{ | ||
primaryKey: <T extends ItemData>({ | ||
collection | ||
}: { | ||
collection: Collection<T> | ||
}): string => { | ||
const item = collection.first() | ||
if (item.type === 'article') { | ||
return 'slug' | ||
} | ||
return 'id' | ||
} | ||
} | ||
``` | ||
|
||
</code-block> | ||
</code-group> | ||
|
||
### `toQuery` | ||
|
||
- Type: `() => Class` | ||
- Arguments: `({ collection, item })` | ||
|
||
If our items are Model classes with Query Builder, we can configure this option to | ||
convert the collection into a Query Builder. | ||
|
||
> This example is from `vue-api-query` integration. | ||
|
||
<code-group> | ||
<code-block label="JavaScript" active> | ||
|
||
```js | ||
{ | ||
toQuery: ({ collection, item }) => { | ||
return item.newModelQuery().whereIn( | ||
collection.primaryKey(), collection.modelKeys() | ||
) | ||
} | ||
} | ||
``` | ||
|
||
</code-block> | ||
<code-block label="TypeScript"> | ||
|
||
```ts | ||
import { Collection, ItemData } from '@eloqjs/collection' | ||
{ | ||
toQuery: <T extends ItemData>({ | ||
collection, | ||
item | ||
}: { | ||
collection: Collection<T> | ||
item: T | ||
}): T => { | ||
const model = item.newModelQuery().whereIn( | ||
collection.primaryKey(), collection.modelKeys() | ||
) | ||
return (model as unknown) as T | ||
} | ||
} | ||
``` | ||
|
||
|
||
</code-block> | ||
</code-group> | ||
|
||
### `fresh` | ||
|
||
- Type: `() => Promise` | ||
- Arguments: `({ collection, include })` | ||
|
||
If our items are Model classes with Query Builder, we can configure this option to | ||
reload a fresh item instance from the database for all the items. | ||
|
||
> This example is from `vue-api-query` integration. | ||
|
||
<code-group> | ||
<code-block label="JavaScript" active> | ||
|
||
```js | ||
{ | ||
fresh: async ({ collection, include }) => { | ||
return await collection.toQuery().include(...include).$get() | ||
} | ||
} | ||
``` | ||
|
||
</code-block> | ||
<code-block label="TypeScript"> | ||
|
||
```ts | ||
import { Collection, ItemData } from '@eloqjs/collection' | ||
{ | ||
fresh: async <T extends ItemData>({ | ||
collection, | ||
include | ||
}: { | ||
collection: Collection<T>, | ||
include: string[] | ||
}): Promise<Collection<T>> => { | ||
const _collection = await collection.toQuery() | ||
.include(...include).$get() | ||
return (_collection as unknown) as Promise<Collection<T>> | ||
} | ||
} | ||
``` | ||
|
||
</code-block> | ||
</code-group> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
title: Introduction | ||
description: The collection for your resources. Made specifically to work with arrays of objects from your API Responses. | ||
position: 1 | ||
category: Getting Started | ||
features: | ||
- Made specifically to work with arrays of objects | ||
- JSON API specification support | ||
- Extends the Array class | ||
- Names and conventions that makes sense | ||
- Models support, fully compatible with vue-api-query, sarala and coloquent | ||
- Integrable `primaryKey`, `fresh` and `toQuery` | ||
- TypeScript support | ||
--- | ||
|
||
<alert type="warning">This documentation still in development.</alert> | ||
|
||
The collection for your resources. Made specifically to work with arrays of objects from your API Responses. | ||
|
||
## Features | ||
|
||
<list :items="features"></list> |
Oops, something went wrong.