
import { observable, computed, toJS } from 'mobx';

// TODO
import fakeFetch from 'utils/fakeFetch';

export default class Store {
	@observable total = 0;
	@observable isFetching = false;
	@observable page = 1;

	@computed get dataSource() {
		return this.collection.get(this.page);
	}

	collections = observable.map();

	size = 20;

	constructor(schema) {
		this._schema = schema;
		this.columns = schema.map(({ title, key, render }) => ({
			title,
			key,
			render,
			dataIndex: key,
		}));
	}

	async fetch(page = 1) {
		if (this.collection.has(page)) { return this; }

		this.isFetching = true;

		const { total, list } = await fakeFetch({
			count: this.size,
		});

		const collection = list.map((data, index) => {

			// TODO: should depend on `schema.unique`
			data.key = data.key || index;

			return data;
		});

		this.page = page;
		this.isFetching = false;
		this.total = total;
		this.collections.set(page, collection);
		return this;
	}
}

@@ -241,24 +241,29 @@
  %7B%0A%09%09return 
+toJS(
 this.collect
@@ -265,16 +265,17 @@
 llection
+s
 .get(thi
@@ -281,16 +281,17 @@
 is.page)
+)
 ;%0A%09%7D%0A%0A%09c
@@ -547,16 +547,17 @@
 llection
+s
 .has(pag

fix store bug