Skip to content
This repository was archived by the owner on Apr 1, 2022. It is now read-only.

Commit b4d9e2a

Browse files
author
Ken Berkeley
committed
purify data in _mockData, in-out
1 parent b635c41 commit b4d9e2a

File tree

6 files changed

+28
-10
lines changed

6 files changed

+28
-10
lines changed

examples/dist/client.dc2c7a28.css

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

examples/dist/client.d8db49e4.js renamed to examples/dist/client.e3ba39eb.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.

examples/dist/client.ed009e18.css

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/dist/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
<title>Vue 2 Datatable Examples</title>
66
<link href="//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
77
<link href="//cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
8-
<link href="client.ed009e18.css" rel="stylesheet"></head>
8+
<link href="client.dc2c7a28.css" rel="stylesheet"></head>
99
<body>
1010

1111
<div id="app"></div>
1212

1313
<script src="//cdn.bootcss.com/jquery/2.1.4/jquery.min.js"></script>
1414
<script src="//cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
15-
<script type="text/javascript" src="client.d8db49e4.js"></script></body>
15+
<script type="text/javascript" src="client.e3ba39eb.js"></script></body>
1616
</html>

examples/src/App.vue

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@
4747
</div>
4848
</div>
4949
</div>
50+
51+
<footer>
52+
Open Devtools - Console to see what Datatable send and receive
53+
</footer>
5054
</div>
5155
</template>
5256
<script>
@@ -65,6 +69,19 @@ export default {
6569
}
6670
</script>
6771
<style>
72+
html {
73+
position: relative;
74+
min-height: 100%;
75+
}
76+
footer {
77+
position: absolute;
78+
left: 0;
79+
right: 0;
80+
bottom: 0;
81+
padding: 5px 0;
82+
text-align: center;
83+
color: #afafaf;
84+
}
6885
.m-t-10 {
6986
margin-top: 10px;
7087
}

examples/src/_mockData/index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ import moment from 'moment'
33
import orderBy from 'lodash/orderBy'
44
import users from './dataSource'
55
const typeOf = o => Object.prototype.toString.call(o).slice(8, -1).toLowerCase()
6+
const purify = o => JSON.parse(JSON.stringify(o)) // purify data
67

78
/**
89
* mockData - simulate Ajax request and respond
910
* @param {Object} query
1011
* @resolve {Object}
1112
*/
1213
export default function mockData(query) {
13-
// default query fields
14-
const { limit = 10, offset = 0, sort = '', order = 'asc' } = query
14+
query = purify(query)
15+
const { limit = 10, offset = 0, sort = '', order = '' } = query
1516

1617
let rows = users;
1718

@@ -33,18 +34,18 @@ export default function mockData(query) {
3334
if (sort) rows = orderBy(rows, sort, order)
3435

3536
const res = {
36-
rows: JSON.parse(JSON.stringify(rows.slice(offset, offset + limit))), // purify data
37+
rows: rows.slice(offset, offset + limit),
3738
total: rows.length,
3839
summary: {
3940
name: rows.length,
4041
age: rows.length && ~~(rows.map(({ age }) => age).reduce((sum, cur) => sum + cur) / rows.length) // average age
4142
}
4243
}
4344

44-
const consoleGroupName = 'Mock data generator - ' + moment().format('YYYY-MM-DD HH:mm:ss')
45+
const consoleGroupName = 'Mock data - ' + moment().format('YYYY-MM-DD HH:mm:ss')
4546
console.group(consoleGroupName)
46-
console.info('Receive:', JSON.stringify(query))
47+
console.info('Receive:', query)
4748
console.info('Respond:', res)
4849
console.groupEnd(consoleGroupName)
49-
return Promise.resolve(res)
50+
return Promise.resolve(purify(res))
5051
}

0 commit comments

Comments
 (0)