From 7dfd0d8373f56718d9a90a39864b21949639224b Mon Sep 17 00:00:00 2001 From: TechQuery Date: Sat, 20 Aug 2022 00:02:13 +0800 Subject: [PATCH] [add] Strapi wrapper document --- ReadMe.md | 8 ++-- package.json | 2 +- source/List.ts | 4 +- test/List.spec.ts | 6 +-- wrapper/Strapi/ReadMe.md | 86 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 96 insertions(+), 10 deletions(-) create mode 100644 wrapper/Strapi/ReadMe.md diff --git a/ReadMe.md b/ReadMe.md index eaaec59..3db55bf 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -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(); ``` @@ -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* () { diff --git a/package.json b/package.json index f55dabe..ac82092 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/source/List.ts b/source/List.ts index ee28a25..dfd0cef 100644 --- a/source/List.ts +++ b/source/List.ts @@ -123,7 +123,7 @@ export abstract class ListModel< } } -export function BufferListModel< +export function Buffer< D extends DataObject, F extends NewData = NewData, M extends AbstractClass> = AbstractClass> @@ -174,7 +174,7 @@ export function BufferListModel< return BufferListMixin; } -export function StreamListModel< +export function Stream< D extends DataObject, F extends NewData = NewData, M extends AbstractClass> = AbstractClass> diff --git a/test/List.spec.ts b/test/List.spec.ts index a457460..0a2e696 100644 --- a/test/List.spec.ts +++ b/test/List.spec.ts @@ -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>; @@ -102,7 +102,7 @@ describe('List model', () => { }); describe('Preload List model', () => { - class PreloadRepositoryModel extends BufferListModel(RepositoryModel) {} + class PreloadRepositoryModel extends Buffer(RepositoryModel) {} const store = new PreloadRepositoryModel(); @@ -110,7 +110,7 @@ describe('List model', () => { }); describe('Multiple List model', () => { - class MultipleRepositoryModel extends StreamListModel(RepositoryModel) { + class MultipleRepositoryModel extends Stream(RepositoryModel) { openStream() { return mergeStream( async function* () { diff --git a/wrapper/Strapi/ReadMe.md b/wrapper/Strapi/ReadMe.md new file mode 100644 index 0000000..b98c2c5 --- /dev/null +++ b/wrapper/Strapi/ReadMe.md @@ -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
{ + 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 ( +
    + {currentPage.map(({ id, title, summary }) => ( +
  • + {title} +

    {summary}

    +
  • + ))} +
+ ); + } +} +``` + +[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