"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.watchPinEvent = void 0;
const _1 = require("../Class/$");
const stringify_1 = require("../spec/stringify");
function watchPinEvent(event, type, pinId, pin, callback) {
    // console.log(event, type, pin)
    const listener = (data) => {
        if (data instanceof _1.$) {
            data = null;
        }
        if (data !== undefined) {
            data = (0, stringify_1.stringify)(data);
        }
        callback({
            type,
            event,
            data: {
                type,
                pinId,
                data,
            },
        });
    };
    pin.prependListener(event, listener);
    return () => {
        pin.removeListener(event, listener);
    };
}
exports.watchPinEvent = watchPinEvent;
//# sourceMappingURL=watchPinEvent.js.map