mahler
Version:
A automated task composer and HTN based planner for building autonomous system agents
39 lines • 1.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Sensor = void 0;
const lens_1 = require("./lens");
const path_1 = require("./path");
const observable_1 = require("./observable");
/**
* Construct a new sensor
*
* This takes an argument either a `SensorProps` object, or just a function.
*
* If a function is passed, it is assumed to be the `sensor` function, and
* the `lens` is assumed to be the root of the state.
*/
function from(input) {
const { lens = '/', sensor = function* () {
/* noop */
}, } = typeof input === 'function' ? { sensor: input } : input;
const lensPath = path_1.Path.from(lens);
return Object.assign(function (path = lens) {
const refPath = path_1.Path.from(path);
const args = lens_1.Lens.args(lensPath, refPath);
return observable_1.Observable.from(sensor(args)).map((target) => ({
op: 'update',
path,
target,
}));
}, { lens: lensPath });
}
function of() {
return {
from,
};
}
exports.Sensor = {
of,
from,
};
//# sourceMappingURL=sensor.js.map