diff --git a/packages/@jsonql/client/README.md b/packages/@jsonql/client/README.md index 3c685fb3ab7f70d8abf0459c378fd40616aec434..3a75700ae39d710e680c399c39c33140c06a01c0 100644 --- a/packages/@jsonql/client/README.md +++ b/packages/@jsonql/client/README.md @@ -1,13 +1,100 @@ # @jsonql/client -> This is jsonql browser client comes with jsonql-client (http) and optional socket clients +> This is jsonql browser client comes with jsonql-client (http) and optional socket clients, plus various modules for ui frameworks ## Example Coming soon +## Vuex module + +We add a vuex store support in version 1.5.19 + +First create a new file (let say call it `jsonql.js`) + +```js +import contract from 'path/to/your/public-contract.json' +import { getJsonqlVuexModule } from '@jsonql/client/vue' +import Fly from 'flyio' + +const jsonqlModule = getJsonqlVuexModule(Fly, { contract }) + +export { jsonqlModule } +``` + +Now in your `store.js` where you define your Vuex store + +```js +import Vue from 'vue' +import Vuex from 'vuex' + +Vue.use(Vuex) + +import { jsonqlModule } from './jsonql' + +export default new Vuex.Store({ + state: {}, + mutations: {}, + actions: {}, + getters: {}, + modules: { + jsonqlModule + } +}) +``` + +This Vuex module is namespaced. In your component + +```html + + +``` + +You might be asking why the resolver name is different from the contract from `query.helloWorld` turn into `queryHelloWorld`. +We use their type to prefix each resolvers, so you might get `query`, `mutation`, `auth` etc. This is to avoid duplicated naming. +You can turn this off by passing a `prefix:false` in the `config` when you set up your store file: + +```js +// the import +const jsonqlModule = getJsonqlVuexModule(Fly, { contract, prefix: false }) +// the export +``` + +### getters getJsonqlResult + +You should notice there is a getter method call `getJsonqlResult` and you pass the resolver name (with prefix or not when you turn it off). +The reason is in the Vuex model, after we call the resolver, we store (commit) the result in our internal `result` state, and key with the resolver name. And whenever a new result return, it will get overwritten, because it's a flat object. + +Of course, you can simply call the actions and wait for the promise to resolve. You will get the same effect. + +### getters getJsonqlError + +Whenever an error happens, we do the same like success result, we commit to our internal `error` state, and you can use this getter to get it. +And after we commit, we will throw it again which wrap in a generic `Error`. So you can also catch it again. + + --- -https://jsonql.org +https://jsonql.org NEWBRAN LTD UK & T01SOURCE CN diff --git a/packages/@jsonql/client/package.json b/packages/@jsonql/client/package.json index cb05bb85d52ef05d35df6c4f35ec5a831a9a44b3..dc6a6074099dfcb373f718aecac69c922077df65 100644 --- a/packages/@jsonql/client/package.json +++ b/packages/@jsonql/client/package.json @@ -1,6 +1,6 @@ { "name": "@jsonql/client", - "version": "0.2.0", + "version": "0.3.0", "description": "jsonql js http and socket client for browser with multiple API for different framework", "main": "dist/jsonql-client.cjs.js", "module": "index.js", @@ -11,7 +11,8 @@ "index.js", "static.js", "ws.js", - "io.js" + "io.js", + "vue" ], "scripts": { "test": "npm run build && npm run test:browser", @@ -46,14 +47,14 @@ "license": "MIT", "dependencies": { "flyio": "^0.6.14", - "jsonql-client": "^1.5.14" + "jsonql-client": "^1.5.18" }, "optionalDependencies": { "@jsonql/ws": "^1.0.11" }, "devDependencies": { - "@jsonql/koa": "^0.8.1", - "ava": "^2.4.0", + "@jsonql/koa": "^0.8.2", + "ava": "^3.3.0", "browser-env": "^3.3.0", "debug": "^4.1.1", "esm": "^3.2.25", @@ -62,14 +63,14 @@ "nyc": "^15.0.0", "promise-polyfill": "8.1.3", "qunit": "^2.9.3", - "rollup": "^1.29.0", + "rollup": "^1.31.1", "rollup-plugin-alias": "^2.2.0", "rollup-plugin-analyzer": "^3.2.2", "rollup-plugin-async": "^1.2.0", "rollup-plugin-buble": "^0.19.8", "rollup-plugin-bundle-size": "^1.0.3", "rollup-plugin-commonjs": "^10.1.0", - "rollup-plugin-copy": "^3.1.0", + "rollup-plugin-copy": "^3.3.0", "rollup-plugin-node-builtins": "^2.1.2", "rollup-plugin-node-globals": "^1.4.0", "rollup-plugin-node-resolve": "^5.2.0", diff --git a/packages/http-client/vuex.js b/packages/@jsonql/client/vue/vuex.js similarity index 100% rename from packages/http-client/vuex.js rename to packages/@jsonql/client/vue/vuex.js diff --git a/packages/http-client/README.md b/packages/http-client/README.md index 539724cf0f38e4486b895c954827d4523756967f..d834c68b16ec8470dad0db6c1e60b62ccf15b697 100644 --- a/packages/http-client/README.md +++ b/packages/http-client/README.md @@ -123,91 +123,6 @@ See the following example (pretty close to our own test version as well) | storageKey | client side local storage key name | `String` | `CLIENT_STORAGE_KEY` | | debugOn | When enable, you will see debug message in your browser console | `Boolean` | `false` | -## Vuex module (1.5.19) - -We add a vuex store support in version 1.5.19 - -First create a new file (let say call it `jsonql.js`) - -```js -import contract from 'path/to/your/public-contract.json' -import { getJsonqlVuexModule } from 'jsonql-client/vuex' -import Fly from 'flyio' - -const jsonqlModule = getJsonqlVuexModule(Fly, { contract }) - -export { jsonqlModule } -``` - -Now in your `store.js` where you define your Vuex store - -```js -import Vue from 'vue' -import Vuex from 'vuex' - -Vue.use(Vuex) - -import { jsonqlModule } from './jsonql' - -export default new Vuex.Store({ - state: {}, - mutations: {}, - actions: {}, - getters: {}, - modules: { - jsonqlModule - } -}) -``` - -This Vuex module is namespaced. In your component - -```html - - -``` - -You might be asking why the resolver name is different from the contract from `query.helloWorld` turn into `queryHelloWorld`. -We use their type to prefix each resolvers, so you might get `query`, `mutation`, `auth` etc. This is to avoid duplicated naming. -You can turn this off by passing a `prefix:false` in the `config` when you set up your store file: - -```js -// the import -const jsonqlModule = getJsonqlVuexModule(Fly, { contract, prefix: false }) -// the export -``` - -### getters getJsonqlResult - -You should notice there is a getter method call `getJsonqlResult` and you pass the resolver name (with prefix or not when you turn it off). -The reason is in the Vuex model, after we call the resolver, we store (commit) the result in our internal `result` state, and key with the resolver name. And whenever a new result return, it will get overwritten, because it's a flat object. - -Of course, you can simply call the actions and wait for the promise to resolve. You will get the same effect. - -### getters getJsonqlError - -Whenever an error happens, we do the same like success result, we commit to our internal `error` state, and you can use this getter to get it. -And after we commit, we will throw it again which wrap in a generic `Error`. So you can also catch it again. --- diff --git a/packages/http-client/package.json b/packages/http-client/package.json index 712c3c245a3550e04a4489d9b5ae30d7563e29f1..14c770c35857e74979a5314b419fe15f8efcf02d 100755 --- a/packages/http-client/package.json +++ b/packages/http-client/package.json @@ -1,6 +1,6 @@ { "name": "jsonql-client", - "version": "1.5.18", + "version": "1.5.19", "description": "jsonql http browser client using Fly.js with full user profile management with jwt and more", "main": "core.js", "module": "index.js", @@ -13,8 +13,7 @@ "index.js", "static.js", "module.js", - "sync.js", - "vuex.js" + "sync.js" ], "scripts": { "test": "ava",