var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { Part } from '../../part.js';
import { PartComponent } from '../../component.js';
import { EventEmitter } from '@kano/common/index.js';
import { property, component } from '../../decorators.js';
import { throttle } from '../../../decorators.js';
import Output from '../../../output/output.js';
class DataComponent extends PartComponent {
    constructor() {
        super(...arguments);
        this.updated = new EventEmitter();
    }
}
__decorate([
    property({ type: EventEmitter, value: new EventEmitter(), noReset: true })
], DataComponent.prototype, "updated", void 0);
const DATA_BASE_URL_KEY = 'data:base-url';
export class DataPart extends Part {
    constructor() {
        super();
        this.value = null;
        this.data = this._components.get('data');
    }
    static getBaseUrl() {
        return Output.config.get(DATA_BASE_URL_KEY, 'https://apps-data.kano.me/data-src/');
    }
    refresh() {
        return this.query()
            .then((data) => {
            this.value = data;
            this.data.updated.fire();
        });
    }
    onStop() {
        super.onStop();
        this.value = null;
    }
    onUpdate(callback) {
        this.data.updated.event(callback, null, this.userSubscriptions);
    }
}
__decorate([
    component(DataComponent)
], DataPart.prototype, "data", void 0);
__decorate([
    throttle(1000, true)
], DataPart.prototype, "refresh", null);
//# sourceMappingURL=data.js.map