Skip to content

Commit d9258fc

Browse files
committed
chore: update configs and codecov
1 parent 6f016b0 commit d9258fc

File tree

8 files changed

+79
-74
lines changed

8 files changed

+79
-74
lines changed

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
[![npm version](https://img.shields.io/npm/v/vue-chimera.svg)](https://www.npmjs.org/package/vue-chimera)
1111
[![npm downloads](https://img.shields.io/npm/dt/vue-chimera.svg)](http://npm-stat.com/charts.html?package=vue-chimera)
1212
[![npm bundle size (minified + gzip)](https://img.shields.io/bundlephobia/minzip/vue-chimera.svg)](https://bundlephobia.com/[email protected])
13-
[![codecov](https://codecov.io/gh/SasanFarrokh/vue-chimera/branch/master/graph/badge.svg)](https://codecov.io/gh/SasanFarrokh/vue-chimera)
13+
[![codecov](https://codecov.io/gh/chimera-js/vue-chimera/branch/master/graph/badge.svg)](https://codecov.io/gh/chimera-js/vue-chimera)
1414

1515
VueJS RESTful client with reactive features.
1616
Vue-Chimera is based on [axios](https://github.com/axios/axios) http client library.
@@ -26,9 +26,6 @@ Overview of features:
2626
- Events
2727
- Lightweight
2828

29-
## Demo
30-
[Demo: vue-chimera](https://cdn.rawgit.com/chimera-js/vue-chimera/f4312e49/example/simple/index.html)
31-
3229
## Documents
3330

3431
[Full Documentation](https://vue-chimera.netlify.com)

build/rollup.config.browser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const config = Object.assign({}, base, {
77
format: 'iife',
88
name: 'VueChimera',
99
globals: {
10-
axios: 'Axios'
10+
axios: 'axios'
1111
}
1212
}
1313
})

build/rollup.config.umd.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const config = Object.assign({}, base, {
77
format: 'umd',
88
name: 'VueChimera',
99
globals: {
10-
axios: 'Axios'
10+
axios: 'axios'
1111
},
1212
exports: 'named'
1313
}

dist/vue-chimera.es.js

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -683,16 +683,14 @@ var Endpoint = /*#__PURE__*/function () {
683683

684684
_this2.setResponse(err, false);
685685

686-
if (_this2.http.isCancelError(err)) {
687-
_this2.emit(CANCEL);
688-
} else {
689-
if (_this2.http.isTimeoutError) {
690-
_this2.emit(TIMEOUT);
691-
}
686+
if (_this2.http.isCancelError(err)) return;
692687

693-
_this2.emit(ERROR);
688+
if (_this2.http.isTimeoutError) {
689+
_this2.emit(TIMEOUT);
694690
}
695691

692+
_this2.emit(ERROR);
693+
696694
throw err;
697695
});
698696
}
@@ -710,8 +708,11 @@ var Endpoint = /*#__PURE__*/function () {
710708
}
711709
}, {
712710
key: "cancel",
713-
value: function cancel() {
714-
this.http.cancel(this);
711+
value: function cancel(silent) {
712+
if (this.loading) {
713+
this.http.cancel(this);
714+
!silent && this.emit(CANCEL);
715+
}
715716
}
716717
}, {
717718
key: "getCacheKey",
@@ -759,7 +760,9 @@ var Endpoint = /*#__PURE__*/function () {
759760
this._interval = ms;
760761
this.stopInterval();
761762
this._interval_id = setInterval(function () {
762-
return _this3.reload(true);
763+
_this3.cancel();
764+
765+
_this3.reload(true);
763766
}, this._interval);
764767
}
765768
}, {
@@ -880,6 +883,7 @@ var VueChimera = /*#__PURE__*/function () {
880883
return Endpoint;
881884
}(Endpoint);
882885

886+
bindVmToEvents(options, this._vm);
883887
LocalEndpoint.prototype.options = LocalEndpoint.applyDefaults(LocalEndpoint.prototype.options, endpointOptions);
884888
Object.assign(this, JSON.parse(JSON.stringify({
885889
deep: deep,
@@ -978,10 +982,11 @@ var VueChimera = /*#__PURE__*/function () {
978982
key: "updateEndpoint",
979983
value: function updateEndpoint(key, newValue, oldValue) {
980984
var oldEndpoint = this.endpoints[key];
981-
var newEndpoint = this.endpointFrom(newValue, oldValue && oldValue.keepData ? oldEndpoint.response : null);
985+
var newEndpoint = this.endpointFrom(newValue, oldEndpoint && oldEndpoint.keepData ? oldEndpoint.response : null);
982986

983987
if (oldValue && oldEndpoint) {
984988
oldEndpoint.stopInterval();
989+
oldEndpoint.cancel(true);
985990
newEndpoint.lastLoaded = oldEndpoint.lastLoaded;
986991
}
987992

@@ -994,32 +999,11 @@ var VueChimera = /*#__PURE__*/function () {
994999
}, {
9951000
key: "endpointFrom",
9961001
value: function endpointFrom(value, initial) {
997-
var _this4 = this;
998-
9991002
if (value == null) return new NullEndpoint();
10001003
if (typeof value === 'string') value = {
10011004
url: value
10021005
};
1003-
1004-
if (isPlainObject(value.on)) {
1005-
var bindVm = function bindVm(handler) {
1006-
if (typeof handler === 'function') {
1007-
handler = handler.bind(_this4._vm);
1008-
}
1009-
1010-
if (typeof handler === 'string') handler = _this4._vm[handler];
1011-
return handler;
1012-
};
1013-
1014-
Object.entries(value.on).forEach(function (_ref2) {
1015-
var _ref3 = _slicedToArray(_ref2, 2),
1016-
event = _ref3[0],
1017-
handlers = _ref3[1];
1018-
1019-
value.on[event] = Array.isArray(handlers) ? handlers.map(bindVm) : bindVm(handlers);
1020-
});
1021-
}
1022-
1006+
bindVmToEvents(value, this._vm);
10231007
var endpoint = new (this.LocalEndpoint || Endpoint)(value, initial);
10241008

10251009
if (!this._server && !initial && endpoint.key && endpoint.prefetch && this._ssrContext) {
@@ -1052,6 +1036,27 @@ var VueChimera = /*#__PURE__*/function () {
10521036
return VueChimera;
10531037
}();
10541038

1039+
function bindVmToEvents(value, vm) {
1040+
if (isPlainObject(value.on)) {
1041+
var bindVm = function bindVm(handler) {
1042+
if (typeof handler === 'function') {
1043+
handler = handler.bind(vm);
1044+
}
1045+
1046+
if (typeof handler === 'string') handler = vm[handler];
1047+
return handler;
1048+
};
1049+
1050+
Object.entries(value.on).forEach(function (_ref2) {
1051+
var _ref3 = _slicedToArray(_ref2, 2),
1052+
event = _ref3[0],
1053+
handlers = _ref3[1];
1054+
1055+
value.on[event] = Array.isArray(handlers) ? handlers.map(bindVm) : bindVm(handlers);
1056+
});
1057+
}
1058+
}
1059+
10551060
var mixin = {
10561061
beforeCreate: function beforeCreate() {
10571062
var _this = this;

dist/vue-chimera.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/vue-chimera.umd.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/guide/installation.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ look sample above.
4949

5050
## Using Script tag (CDN)
5151
```html
52+
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.19.2/axios.min.js"></script>
5253
<script src="https://unpkg.com/vue-chimera@latest/dist/vue-chimera.min.js"></script>
5354
```
5455
If you use old browser style and `Vue` is publicly exposed as global variable

example/browser/index.html

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ <h1>Vue-Chimera</h1>
4545
<div class="con">
4646
<h3>Simple GET</h3>
4747
<p>
48-
<span v-if="!$chimera.simple.loading && $chimera.simple.data">{{ $chimera.simple.data.title }}</span>
48+
<span v-if="!simpleGet.loading && simpleGet.data">{{ simpleGet.data.title }}</span>
4949
<span v-else>Loading...</span>
5050
</p>
5151
<pre>
52-
resources: {
53-
myResource: '/api/v1/posts/1'
52+
chimera: {
53+
simpleGet: '/api/v1/posts/1'
5454
}
5555
</pre>
5656
</div>
@@ -59,12 +59,14 @@ <h3>Simple GET</h3>
5959
<h3>Reactive GET</h3>
6060
Post id: <input type="number" v-model="postId">
6161
<p>
62-
<span v-if="!$chimera.reactive.loading && $chimera.reactive.data">{{ $chimera.reactive.data.title }}</span>
63-
<small v-if="$chimera.reactive.loading">Loading...</small>
62+
<span v-if="!reactiveGet.loading && reactiveGet.data">{{ reactiveGet.data.title }}</span>
63+
<small v-if="reactiveGet.loading">Loading...</small>
6464
</p>
6565
<pre>
66-
resources: {
67-
myResource: () => `/api/v1/posts/${this.postId}`,
66+
chimera: {
67+
reactiveGet() {
68+
return `/api/v1/posts/${this.postId}`
69+
},
6870
}
6971
</pre>
7072
</div>
@@ -74,72 +76,72 @@ <h3>Simple GET with auto refresh interval</h3>
7476
<p>
7577
Current UTC time:
7678
<span style="font-family: arial;"
77-
v-if="$chimera.time.data">Last loaded: {{ $chimera.time.lastLoaded }}</span>
78-
<small v-if="$chimera.time.loading">Refreshing...</small>
79+
v-if="time.data">Last loaded: {{ time.lastLoaded }}</span>
80+
<small v-if="time.loading">Refreshing...</small>
7981
</p>
8082
<pre>
81-
resources: {
82-
myResource: '/api/v1/posts/1',
83-
interval: 2000
83+
chimera: {
84+
time: {
85+
url: '/api/v1/posts/1',
86+
interval: 2000
87+
}
8488
}
8589
</pre>
8690
</div>
8791

8892
<div class="con">
89-
<h3>POST Without prefetch</h3>
93+
<h3>POST with manual send</h3>
9094
<p>
91-
<span v-if="!$chimera.prefetch.loading && $chimera.prefetch.data">
95+
<span v-if="!manual.loading && manual.data">
9296
<span style="color: #4cbd51">Successfully created:</span>
93-
{{ $chimera.prefetch.data.name }}
94-
{{ $chimera.prefetch.data.job }}
97+
{{ manual.data.name }}
98+
{{ manual.data.job }}
9599
</span>
96100
</p>
97101
<div>
98-
<button v-if="!$chimera.prefetch.lastLoaded" @click="load">Execute</button>
99-
<small v-if="$chimera.prefetch.loading">Loading...</small>
102+
<button v-if="!manual.lastLoaded" @click="load">Execute</button>
103+
<small v-if="manual.loading">Loading...</small>
100104
</div>
101105
<pre>
102-
resources: {
103-
myResource: '/api/v1/posts/1',
104-
prefetch: false
106+
chimera: {
107+
manual: {
108+
url: '/api/v1/posts/1',
109+
auto: false
110+
}
105111
}
106112
</pre>
107113
</div>
108114
</div>
109115

110116
</div>
111117
</body>
112-
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.min.js"></script>
113-
<!--<script src="https://unpkg.com/[email protected]/dist/vue-chimera.js"></script>-->
118+
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.11/vue.min.js"></script>
119+
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.19.2/axios.min.js"></script>
114120
<script src="../../dist/vue-chimera.min.js"></script>
115121
<script>
122+
Vue.use(VueChimera)
116123
var app = new Vue({
117124
el: '#app',
118125

119126
chimera: {
120-
121-
$options: {
122-
prefetch: true,
123-
},
124-
125-
simple: 'https://idehhub.com/api/v1/blog/posts/55?lang=en',
127+
simpleGet: 'https://idehhub.com/api/v1/blog/posts/55?lang=en',
126128
time: {
127129
url: 'https://reqres.in/api/users',
128130
interval: 2000,
129131
},
130132

131-
reactive: function () {
133+
reactiveGet: function () {
132134
return 'https://idehhub.com/api/v1/blog/posts/' + this.postId + '?lang=en'
133135
},
134136

135-
prefetch: {
137+
manual: {
136138
url: 'https://reqres.in/api/users',
137139
method: 'POST',
138140
params: {
139141
'name': 'morpheus',
140142
'job': 'leader'
141143
},
142-
prefetch: false
144+
auto: false
143145
}
144146
},
145147

@@ -149,7 +151,7 @@ <h3>POST Without prefetch</h3>
149151

150152
methods: {
151153
load: function () {
152-
this.$chimera.prefetch.execute()
154+
this.$chimera.manual.fetch()
153155
}
154156
}
155157
})

0 commit comments

Comments
 (0)