1 | const serialTypes = new Set([Boolean, String, Number]);
|
2 |
|
3 | export default function() {
|
4 | var model = this,
|
5 | data = {},
|
6 | keys = Array.from(this.$events.keys()).concat(Object.keys(this)),
|
7 | value;
|
8 |
|
9 | keys.forEach(key => {
|
10 | if (key && key.substring(0, 1) !== "$") {
|
11 | value = getValue(model[key]);
|
12 | if (value !== undefined) data[key] = value;
|
13 | }
|
14 | });
|
15 | return data;
|
16 | }
|
17 |
|
18 | function getValue(value) {
|
19 | if (!value) return value;
|
20 | else if (value.constructor === Array) return value.map(getValue);
|
21 | else if (typeof value.$data === "function") return value.$data();
|
22 | else if (serialTypes.has(value.constructor)) return value;
|
23 | }
|