Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs #16

Draft
wants to merge 3 commits into
base: dev
Choose a base branch
from
Draft

docs #16

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/content/en/api/methods.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: Methods
description: List of all methods of @eloqjs/collection.
category: API
position: 6
---

<alert type="warning">This documentation still in development. Not all methods are yet listed.</alert>
152 changes: 152 additions & 0 deletions docs/content/en/api/options.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
---
title: Options
description: List of all options of @eloqjs/collection.
category: API
position: 5
---

### `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>
155 changes: 6 additions & 149 deletions docs/content/en/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ position: 3

<alert type="info">If you are using **Nuxt** or **Vue**, please follow their configuration steps instead of this one.</alert>

See the [API reference](/api/options) for a list of available options.

You can configure `@eloqjs/collection` with the `Collection.config` property in `src/main.js`.

```js{}[src/main.js]
Expand All @@ -25,6 +27,8 @@ Collection.config = {

<alert type="warning">The nuxt module [@eloqjs/nuxt-collection](https://github.com/eloqjs/nuxt-collection) will be released soon.</alert>

See the [API reference](/api/options) for a list of available options.

You can configure `@eloqjs/nuxt-collection` with the `collection` property in your `nuxt.config.js`.

```js{}[nuxt.config.js]
Expand All @@ -37,6 +41,8 @@ export default {

### Vue

See the [API reference](/api/options) for a list of available options.

You can configure `@eloqjs/vue-collection` by passing the options to `Vue.use` in `src/main.js`.

```js{}[src/main.js]
Expand All @@ -47,152 +53,3 @@ 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>
11 changes: 6 additions & 5 deletions docs/content/en/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ position: 4

<alert type="warning">This documentation still in development.</alert>

See the [API reference](/api/methods) for a list of available methods.

<code-group>
<code-block label="collect()" active>

Expand Down Expand Up @@ -38,6 +40,8 @@ position: 4

<alert type="warning">The nuxt module [@eloqjs/nuxt-collection](https://github.com/eloqjs/nuxt-collection) will be released soon.</alert>

See the [API reference](/api/methods) for a list of available methods.

The module globally injects `$collect` instance, meaning that you can access it anywhere
using `this.$collect`. For plugins, asyncData, nuxtServerInit and Middleware, you can access it from `context.$collect`.

Expand All @@ -64,6 +68,8 @@ using `this.$collect`. For plugins, asyncData, nuxtServerInit and Middleware, yo

### Vue

See the [API reference](/api/methods) for a list of available methods.

The plugin globally injects `$collect` instance, meaning that you can access it anywhere
using `this.$collect`. You can also access it from `Vue.collect`.

Expand All @@ -87,8 +93,3 @@ using `this.$collect`. You can also access it from `Vue.collect`.

</code-block>
</code-group>

## Methods

<alert type="warning">This documentation still in development. Not all methods are yet listed.</alert>