Skip to content

Commit

Permalink
wrap ky in object, add helper method for setting current title (#638)
Browse files Browse the repository at this point in the history
  • Loading branch information
basejump authored Dec 1, 2021
1 parent 4b0f00d commit a5a3b0a
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 33 deletions.
4 changes: 2 additions & 2 deletions babel.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
}
],
[ // required for svelte-jsx and svelte-fragment-component
'@babel/plugin-transform-react-jsx',
{runtime: 'automatic', importSource: 'svelte-jsx'}
"@babel/plugin-transform-react-jsx",
{"runtime": "automatic", "importSource": "svelte-jsx"}
]
]
}
2 changes: 1 addition & 1 deletion examples/demo/src/app.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import appName from './app.module'
import './config.router'
import appState from 'angle-grinder/src/tools/AppState'
import {setConfig} from 'angle-grinder/src/tools/AppConfig'
import {setClientConfig} from "angle-grinder/src/dataApi/ky";
import {setClientConfig} from "angle-grinder/src/dataApi/kyClient";

const app = angular.module(appName)
// export default app.name
Expand Down
10 changes: 9 additions & 1 deletion examples/demo/src/svelte/Lists/ListSimple.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script>
import { Avatar, Columns, Col, BlockTitle, Card, CardContent, Icon, List, ListItem } from 'angle-grinder/svelte'
import { SkeletonBlock } from 'skeleton-elements/svelte';
let simpleList = ['Item 1', 'Item 2', 'Item 3']
let dataList = [
{name: 'DSO', val: 39},
Expand Down Expand Up @@ -59,6 +59,14 @@
<BlockTitle>Contact List</BlockTitle>
<Card>
<CardContent class="p0">
<List mediaList v-if="loading">
<ListItem class={`skeleton-text skeleton-effect-wave`} title="Full Name" subtitle="Position">
<span slot="media">

<SkeletonBlock style="width: 40px; height: 40px; border-radius: 50%" />
</span>
</ListItem>
</List>
<List>
<ListItem link={noref} header="Name" title="John Doe">
<Avatar slot="media" class="is-small" imgSrc="/assets/images/photos/beard-guy.jpg"></Avatar>
Expand Down
2 changes: 1 addition & 1 deletion examples/grails-demo/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import './app.config'
import './AppCtrl'

import './grids'
import {setClientConfig} from 'angle-grinder/src/dataApi/ky'
import {setClientConfig} from 'angle-grinder/src/dataApi/kyClient'

setClientConfig({prefixUrl: 'http://localhost:8080'})
$log.debugEnabled(true)
4 changes: 2 additions & 2 deletions src/dataApi/AppConfigApi.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { client as ky } from './ky'
import kyApi from './kyClient'

class LocalCache {
_values = {}
Expand Down Expand Up @@ -45,7 +45,7 @@ export class AppConfigApi {
if (_cache.contains(key)) {
return _cache.get(key)
} else {
const cfg = await ky.get(key).json()
const cfg = await kyApi.client.get(key).json()
_cache.set(key, cfg)
return cfg
}
Expand Down
8 changes: 6 additions & 2 deletions src/dataApi/RestDataApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ export default class RestDataApi {
*
* @param prefixUrl The endpoint url prefix ex: /api or http://foo.com/api
*/
constructor(endpoint, api) {
constructor(endpoint, kyApi) {
// this.prefixUrl = prefixUrl
this.endpoint = endpoint
// this.api = ky.create({prefixUrl: prefixUrl});
this._idProp = 'id'
this.api = api || ky
this.kyApi = kyApi
}

get api(){
return this.kyApi.client || ky
}

//
Expand Down
24 changes: 0 additions & 24 deletions src/dataApi/ky.js

This file was deleted.

30 changes: 30 additions & 0 deletions src/dataApi/kyClient.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import ky from 'ky'
import globalLoader from '../tools/globalLoader'


// we wrap it like this so we can import the same instance
// and when setClientConfig it will set it up and then every where its used
// can ref it with kyApi.client and it will get the same reference
const kyApi = {
client:{}
}

const defaultKy = ky.extend({
hooks: {
beforeRequest: [
request => {
globalLoader.start()
}
],
afterResponse: [
(_request, _options, response) => {
globalLoader.complete()
}]
}
})

export const setClientConfig = (config) => {
kyApi.client = defaultKy.extend(config)
}

export default kyApi
3 changes: 3 additions & 0 deletions src/styles/framework7/framework7.less
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,6 @@
@import '~framework7/components/input/input.less';
@import '~framework7/components/calendar/calendar.less';
@import '~framework7/components/popover/popover.less';

//misc
@import '~framework7/components/skeleton/skeleton.less';
4 changes: 4 additions & 0 deletions src/tools/AppState.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ class AppState {
return this.$state.current?.data?.title
}

setCurrentTitle(dataTitle) {
this.$state.current.data.title = dataTitle
}

/**
* construct the page title from app name and title to show on head and browser tab
*/
Expand Down

0 comments on commit a5a3b0a

Please sign in to comment.