Innovenergy_trunk/frontend/node_modules/testcafe/lib/client-functions/replicator.js

62 lines
6.0 KiB
JavaScript

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SelectorNodeTransform = exports.FunctionTransform = exports.createReplicator = void 0;
const lodash_1 = require("lodash");
const replicator_1 = __importDefault(require("replicator"));
const builder_symbol_1 = __importDefault(require("./builder-symbol"));
const compile_client_function_1 = __importDefault(require("../compiler/compile-client-function"));
function createReplicator(transforms) {
// NOTE: we will serialize replicator results
// to JSON with a command or command result.
// Therefore there is no need to do additional job here,
// so we use identity functions for serialization.
const replicator = new replicator_1.default({
serialize: lodash_1.identity,
deserialize: lodash_1.identity,
});
return replicator.addTransforms(transforms);
}
exports.createReplicator = createReplicator;
// Replicator transforms
class FunctionTransform {
constructor(callsiteNames) {
this.type = 'Function';
this.callsiteNames = callsiteNames;
}
shouldTransform(type) {
return type === 'function';
}
toSerializable(fn) {
const clientFnBuilder = fn[builder_symbol_1.default];
if (clientFnBuilder) {
return {
fnCode: clientFnBuilder.compiledFnCode,
dependencies: clientFnBuilder.getFunctionDependencies(),
};
}
return {
fnCode: (0, compile_client_function_1.default)(fn.toString(), null, this.callsiteNames.instantiation, this.callsiteNames.execution),
dependencies: {},
};
}
fromSerializable() {
return void 0;
}
}
exports.FunctionTransform = FunctionTransform;
class SelectorNodeTransform {
constructor() {
this.type = 'Node';
}
shouldTransform() {
return false;
}
fromSerializable(nodeSnapshot) {
return nodeSnapshot;
}
}
exports.SelectorNodeTransform = SelectorNodeTransform;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVwbGljYXRvci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9jbGllbnQtZnVuY3Rpb25zL3JlcGxpY2F0b3IuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs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