proto-sudoku-wc 0.0.484 → 0.0.486

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import { createStore } from '@stencil/store';
2
- import axios from 'axios';
2
+ import ky from 'ky';
3
3
  import { bag } from './bag';
4
4
  // --------------------------------------------------------[ mutable store ]
5
5
  const storeDef = {
@@ -136,10 +136,17 @@ const processPick = (next) => {
136
136
  savePick(state.pick);
137
137
  };
138
138
  // --------------------------------------------------------[ utils ]
139
- const api = axios.create({
140
- baseURL: 'https://sudoku-rust-api.vercel.app/api/',
139
+ const api = ky.extend({
140
+ hooks: {
141
+ beforeRequest: [
142
+ request => {
143
+ request.headers.set('X-Requested-With', 'ky');
144
+ request.headers.set('X-Custom-Header', 'foobar');
145
+ },
146
+ ],
147
+ },
148
+ prefixUrl: 'https://sudoku-rust-api.vercel.app/api',
141
149
  timeout: 10000,
142
- headers: { 'X-Custom-Header': 'foobar' },
143
150
  });
144
151
  const saveInputs = (inputs) => {
145
152
  bag.inputs.store(inputs);
@@ -180,27 +187,26 @@ const initApp = () => {
180
187
  }
181
188
  }
182
189
  };
183
- const refresh = () => {
190
+ const refresh = async () => {
184
191
  clearStore(true);
185
192
  saveInputs([]);
186
193
  savePick(state.pick);
187
- // fetch a new puzzle from the api...
188
- api
189
- .get('/puzzle')
190
- .then(({ data }) => {
194
+ try {
195
+ // fetch a new puzzle from the api...
196
+ const data = await api.get('puzzle').json();
191
197
  updateStore(data);
192
- })
193
- .catch(error => {
198
+ }
199
+ catch (err) {
194
200
  // handle error...
195
- const { message } = error;
201
+ const { message } = err;
196
202
  console.log('-- ', message);
197
- console.log(error);
203
+ console.log(err);
198
204
  state.error = message;
199
- })
200
- .then(() => {
205
+ }
206
+ finally {
201
207
  // always executed
202
208
  state.loading = false;
203
- });
209
+ }
204
210
  };
205
211
  const select = (cell) => {
206
212
  processPick(cell);