export class BaseDataSource {
    constructor(data) {
        this.data = data;
    }
    /**
     * Editing
     */
    async patch(options) {
        for (const action in options.patch) {
            if (options.patch.hasOwnProperty(action)) {
                options.patch[action].forEach(data => this[action](data, options));
            }
        }
        return (options.patch.create || options.patch.update) ? this.sort(options) : this.paginate(options);
    }
    create(data) {
        this.data.unshift(data);
    }
    delete(data) {
        this.data = this.data.filter(d => d !== data);
    }
    update(data, options) {
        const index = this.data.findIndex(d => d[options.key] === data[options.key]);
        this.data[index] = data;
    }
}
