"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.watchRefPinEvent = watchRefPinEvent;
const stringify_1 = require("../spec/stringify");
function watchRefPinEvent(event, type, pinType, pinId, pin, callback) {
    // console.log(event, type, pin)
    const listener = (_data) => {
        const data = (0, stringify_1.stringify)(_data, true);
        callback({
            type,
            event,
            data: { type: pinType, pinId, data },
        });
    };
    if (event === 'data') {
        if (pin.active()) {
            const _data = pin.peak();
            listener(_data);
        }
    }
    pin.prependListener(event, listener);
    return () => {
        pin.removeListener(event, listener);
    };
}
//# sourceMappingURL=watchRefPinEvent.js.map