Skip to content

Commit

Permalink
[add] Strapi wrapper document
Browse files Browse the repository at this point in the history
  • Loading branch information
TechQuery committed Aug 19, 2022
1 parent f7512f6 commit 7dfd0d8
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 10 deletions.
8 changes: 4 additions & 4 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ export class RepositoryPage extends WebCell() {

```typescript
import { buildURLData } from 'web-utility';
import { BufferListModel } from 'mobx-restful';
import { Buffer } from 'mobx-restful';

import { RepositoryModel } from './Repository';

export class PreloadRepositoryModel extends BufferListModel(RepositoryModel) {}
export class PreloadRepositoryModel extends Buffer(RepositoryModel) {}

export default new PreloadRepositoryModel();
```
Expand All @@ -114,11 +114,11 @@ export default new PreloadRepositoryModel();

```typescript
import { buildURLData, mergeStream } from 'web-utility';
import { StreamListModel } from 'mobx-restful';
import { Stream } from 'mobx-restful';

import { Repository, RepositoryModel } from './Repository';

export class MultipleRepository extends StreamListModel(RepositoryModel) {
export class MultipleRepository extends Stream(RepositoryModel) {
openStream() {
return mergeStream(
async function* () {
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": "mobx-restful",
"version": "0.6.0-rc.2",
"version": "0.6.0-rc.3",
"license": "LGPL-3.0",
"author": "shiy2008@gmail.com",
"description": "MobX SDK for RESTful API",
Expand Down
4 changes: 2 additions & 2 deletions source/List.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export abstract class ListModel<
}
}

export function BufferListModel<
export function Buffer<
D extends DataObject,
F extends NewData<D> = NewData<D>,
M extends AbstractClass<ListModel<D, F>> = AbstractClass<ListModel<D, F>>
Expand Down Expand Up @@ -174,7 +174,7 @@ export function BufferListModel<
return BufferListMixin;
}

export function StreamListModel<
export function Stream<
D extends DataObject,
F extends NewData<D> = NewData<D>,
M extends AbstractClass<ListModel<D, F>> = AbstractClass<ListModel<D, F>>
Expand Down
6 changes: 3 additions & 3 deletions test/List.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isEmpty, buildURLData, mergeStream } from 'web-utility';

import { NewData } from '../source/utility/type';
import { BufferListModel, ListModel, StreamListModel } from '../source/List';
import { ListModel, Buffer, Stream } from '../source/List';
import { client } from './service';

type Repository = Record<'full_name' | 'html_url', string>;
Expand Down Expand Up @@ -102,15 +102,15 @@ describe('List model', () => {
});

describe('Preload List model', () => {
class PreloadRepositoryModel extends BufferListModel(RepositoryModel) {}
class PreloadRepositoryModel extends Buffer(RepositoryModel) {}

const store = new PreloadRepositoryModel();

// Type checking for now
});

describe('Multiple List model', () => {
class MultipleRepositoryModel extends StreamListModel(RepositoryModel) {
class MultipleRepositoryModel extends Stream(RepositoryModel) {
openStream() {
return mergeStream(
async function* () {
Expand Down
86 changes: 86 additions & 0 deletions wrapper/Strapi/ReadMe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# MobX-Strapi

[MobX][1] SDK for [Strapi][2] v4 (headless CMS)

[![](https://raw.githubusercontent.com/sindresorhus/awesome/main/media/mentioned-badge.svg)][5]

[![NPM](https://nodei.co/npm/mobx-strapi.png?downloads=true&downloadRank=true&stars=true)][6]

## Usage

```shell
npm i mobx-restful mobx-strapi koajax
```

### `model/service.ts`

```javascript
import { HTTPClient } from 'koajax';

export const strapiClient = new HTTPClient({
baseURI: 'http://your.production.domain/path/optional',
responseType: 'json'
});
```

### `model/Article.ts`

```typescript
import { StrapiListModel } from 'mobx-strapi';

import { strapiClient } from './service';

export type Article = Record<'id' | 'title' | 'summary', string>;

export class ArticleModel extends StrapiListModel<Article> {
client = strapiClient;
baseURI = 'articles';
}

export default new ArticleModel();
```

### `page/Article/index.tsx`

Use [WebCell][7] as an Example

```tsx
import { WebCell, component, observer, createCell } from 'web-cell';

import articleStore from '../../model/Article';

@component({
tagName: 'article-page'
})
@observer
export class ArticlePage extends WebCell() {
connectedCallback() {
articleStore.getList();
}

disconnectedCallback() {
articleStore.clear();
}

render() {
const { currentPage } = articleStore;

return (
<ul>
{currentPage.map(({ id, title, summary }) => (
<li>
<a href={`#/article/${id}`}>{title}</a>
<p>{summary}</p>
</li>
))}
</ul>
);
}
}
```

[1]: https://mobx.js.org/
[2]: https://strapi.io/
[5]: https://github.com/strapi/awesome-strapi
[6]: https://nodei.co/npm/mobx-strapi/
[7]: https://github.com/EasyWebApp/WebCell

0 comments on commit 7dfd0d8

Please sign in to comment.