Example #1
0
    reset: function () {

        this.state = {
            results: CloneDeep(this.defaultState.results),
            createNew: CloneDeep(this.defaultState.createNew),
            details: CloneDeep(this.defaultState.details),
            permissions: CloneDeep(this.defaultState.permissions),
            delete: CloneDeep(this.defaultState.delete)
        };
    },
Example #2
0
 function callPostRender(renderedFiles) {
   if (typeof args.postRender === 'function') {
     console.log(chalk.yellow('post render…'));
     return Promise.resolve(args.postRender(cloneDeep(renderedFiles)));
   }
   return renderedFiles;
 }
Example #3
0
  static deleteCaption(graph, captionId) {
    let newGraph = cloneDeep(graph);

    delete newGraph.captions[captionId];

    return newGraph;
  }
Example #4
0
  static deleteEdge(graph, edgeId) {
    let newGraph = cloneDeep(graph);

    delete newGraph.edges[edgeId];

    return newGraph;
  }
Example #5
0
  static setHighlights(graph, highlights, otherwiseFaded = false) {
    if (highlights.nodeIds.length + highlights.edgeIds.length + highlights.captionIds.length == 0) {
      otherwiseFaded = false;
    }

    let { nodeIds, edgeIds, captionIds } = highlights;
    let otherwise = otherwiseFaded ? "faded" : "normal";
    let newGraph = cloneDeep(graph);

    // cast all ids to strings
    nodeIds = nodeIds.map(id => String(id));
    edgeIds = edgeIds.map(id => String(id));
    captionIds = captionIds.map(id => String(id));

    values(newGraph.nodes).forEach(node => {
      newGraph.nodes[node.id].display.status = includes(nodeIds, String(node.id)) ? "highlighted" : otherwise;
    });

    values(newGraph.edges).forEach(edge => {
      newGraph.edges[edge.id].display.status = includes(edgeIds, String(edge.id)) ? "highlighted" : otherwise;
    });

    values(newGraph.captions).forEach(caption => {
      newGraph.captions[caption.id].display.status = includes(captionIds, String(caption.id)) ? "highlighted" : otherwise;
    });

    return newGraph;
  };
Example #6
0
export function template(name: string, nodes?: Array<Object>, keepExpression?: boolean): Object {
  var ast = exports.templates[name];
  if (!ast) throw new ReferenceError(`unknown template ${name}`);

  if (nodes === true) {
    keepExpression = true;
    nodes = null;
  }

  ast = cloneDeep(ast);

  if (!isEmpty(nodes)) {
    traverse(ast, templateVisitor, null, nodes);
  }

  if (ast.body.length > 1) return ast.body;

  var node = ast.body[0];

  if (!keepExpression && t.isExpressionStatement(node)) {
    return node.expression;
  } else {
    return node;
  }
}
Example #7
0
  static deleteEdges(graph, edgeIds) {
    let newGraph = cloneDeep(graph);

    edgeIds.forEach(id => delete newGraph.edges[id]);

    return newGraph;
  }
Example #8
0
function transformData(fn, templateKey, originalData) {
  if (!fn) {
    return originalData;
  }

  let clonedData = cloneDeep(originalData);

  let data;
  const typeFn = typeof fn;
  if (typeFn === 'function') {
    data = fn(clonedData);
  } else if (typeFn === 'object') {
    // ex: transformData: {hit, empty}
    if (fn[templateKey]) {
      data = fn[templateKey](clonedData);
    } else {
      // if the templateKey doesn't exist, just use the
      // original data
      data = originalData;
    }
  } else {
    throw new Error(`transformData must be a function or an object, was ${typeFn} (key : ${templateKey})`);
  }

  let dataType = typeof data;
  let expectedType = typeof originalData;
  if (dataType !== expectedType) {
    throw new Error(`\`transformData\` must return a \`${expectedType}\`, got \`${dataType}\`.`);
  }
  return data;
}
Example #9
0
  static deleteCaptions(graph, captionIds) {
    let newGraph = cloneDeep(graph);

    captionIds.forEach(id => delete newGraph.captions[id]);

    return newGraph;
  }
Example #10
0
  // GRAPH FILTERS

  // removes unconnected nodes
  static prune(graph) {
    let newGraph = cloneDeep(graph);
    let connectedNodeIds = flatten(values(newGraph.edges).map(edge => [edge.node1_id, edge.node2_id]));
    let orphanNodeIds = difference(Object.keys(newGraph.nodes).map(nodeId => parseInt(nodeId)), connectedNodeIds);
    orphanNodeIds.forEach(nodeId => delete newGraph.nodes[nodeId]);
    return newGraph;
  }
Example #11
0
  static forceLayout(graph, steps = 500) {
    // only use force layout if there are unpositioned nodes
    if (!values(graph.nodes).find(n => !(isNumber(n.display.x) && isNumber(n.display.y)))) {
      return graph;
    }

    let layout = this.buildForceLayout(graph);
    let nodeCount = Object.keys(graph.nodes).length;
    let edgeCount = Object.keys(graph.edges).length

    steps = Math.round(steps / ((nodeCount + edgeCount) / 50));

    for (var i = 0; i < steps; i++) {
      layout.tick(0.01);
    }

    let newGraph = cloneDeep(graph);

    layout.eachNode((node, point) => {
      newGraph.nodes[node.data.label].display.x = point.p.x * 100;
      newGraph.nodes[node.data.label].display.y = point.p.y * 100;
    });

    // remove curve control points so that they're recalculated
    Object.keys(newGraph.edges).forEach(id => {
      delete newGraph.edges[id].display.cx;
      delete newGraph.edges[id].display.cy;
    });

    return newGraph;
  }
Example #12
0
exports.template = function (name, nodes, keepExpression) {
  var template = exports.templates[name];
  if (!template) throw new ReferenceError("unknown template " + name);

  if (nodes === true) {
    keepExpression = true;
    nodes = null;
  }

  template = cloneDeep(template);

  if (!isEmpty(nodes)) {
    traverse(template, templateVisitor, null, nodes);
  }

  if (template.body.length > 1) return template.body;

  var node = template.body[0];

  if (!keepExpression && t.isExpressionStatement(node)) {
    return node.expression;
  } else {
    return node;
  }
};
Example #13
0
// The base client provides the general structure
// for a dialect specific client object.
function Client(config) {
  config = config || {}
  this.config = config
  this.connectionSettings = cloneDeep(config.connection || {})
  if (this.driverName && config.connection) {
    this.initializeDriver()
    this.initializePool(config)
  }
}
Example #14
0
  // limits graph to set of nodes and the edges between them
  static limitGraphToNodeIds(graph, nodeIds) {
    let filteredGraph = cloneDeep(graph);

    filteredGraph.nodes = nodeIds.reduce((result, nodeId) => merge(result, { [nodeId]: graph.nodes[nodeId] }), {});
    filteredGraph.edges = this.edgesBetweenNodes(graph, nodeIds)
                              .reduce((result, edge) => merge(result, { [edge.id]: edge }), {});

    return filteredGraph;
  }
Example #15
0
  static deleteNodes(graph, nodeIds) {
    let newGraph = cloneDeep(graph);
    let edgeIds = flatten(nodeIds.map(id => this.edgesConnectedToNode(graph, id).map(edge => edge.id)));

    edgeIds.forEach(id => delete newGraph.edges[id]);
    nodeIds.forEach(id => delete newGraph.nodes[id]);

    return newGraph;
  }
Example #16
0
  function callRender(file, index, allFiles) {
    var currentFolder = path.join(file.path, '..');
    var folderPattern = (currentFolder === '.')
      ? REGEX_NO_FOLDER
      : new RegExp('^'+currentFolder+'\/[^\/]+(\/index)?$');

    var filesInCurrentFolder = allFiles.filter(function(testedFile) {
      return folderPattern.test(testedFile.path) && testedFile.path !== file.path;
    });

    var destinationPath = path.join(args.html, file.path+'.html');

    console.log(chalk.yellow('rendering '+file.path));
    var clonedFile = cloneDeep(file);
    return Promise.resolve(
        args.render(clonedFile, cloneDeep(filesInCurrentFolder), cloneDeep(allFiles))
      )
      .then(writeFile(destinationPath, clonedFile));
  }
 function selectiveCloneDeep(obj) {
   return cloneDeep(obj, function(value) {
     if (isObject(value)) {
       if (!isArray(value)) {
         let omitKeys = ["loc", "start", "end", "tokens", "children", "tokenStart", "tokenEnd"];
         if (value.comments && !value.comments.length) { omitKeys.push("comments"); }
         return mapValues(omit(value, omitKeys), selectiveCloneDeep);
       }
     }
   });
 }
// The base client provides the general structure
// for a dialect specific client object.
function Client() {
  var config = arguments[0] === undefined ? {} : arguments[0];

  this.config = config;
  this.connectionSettings = cloneDeep(config.connection || {});
  if (this.driverName && config.connection) {
    this.initializeDriver();
    if (!config.pool || config.pool && config.pool.max !== 0) {
      this.initializePool(config);
    }
  }
}
Example #19
0
 printableProperties.forEachWithProperty(function(key) {
   var value = this[key];
   if (key === 'availableOptions') {
     value = cloneDeep(value);
     value.forEach(function(option) {
       if (typeof option.type === 'function') {
         option.type = option.type.name;
       }
     });
   }
   json[key] = value;
 }, this);
Example #20
0
  // ETC

  // groups multiple edges between the same nodes (regardless of direction) into one edge
  static bundleEdges(graph) {
    let edges = values(graph.edges).reduce((result, edge) => {
      let idHash = [edge.node1_id, edge.node2_id].sort()[0].toString() + ":" + 
                   [edge.node1_id, edge.node2_id].sort()[1].toString();
      result[idHash] = edge; // Edge.combine(edge, result[idHash]);
      return result;
    }, {});

    let bundledGraph = cloneDeep(graph);
    bundledGraph.edges = values(edges).reduce((result, edge) => merge(result, { [edge.id]: edge }), {});

    return bundledGraph;
  }
Example #21
0
    reset: function () {

        this.state = {
            results: CloneDeep(this.defaultState.results),
            createNew: CloneDeep(this.defaultState.createNew),
            details: CloneDeep(this.defaultState.details),
            user: CloneDeep(this.defaultState.user),
            status: CloneDeep(this.defaultState.status),
            note: CloneDeep(this.defaultState.note),
            delete: CloneDeep(this.defaultState.delete)
        };
    },
Example #22
0
function useTemplate(ast, nodes?: Array<Object>) {
  ast = cloneDeep(ast);
  let { program } = ast;

  if (nodes.length) {
    traverse(ast, templateVisitor, null, nodes);
  }

  if (program.body.length > 1) {
    return program.body;
  } else {
    return program.body[0];
  }
}
Example #23
0
// The base client provides the general structure
// for a dialect specific client object.
function Client(config = {}) {
  this.config = config
  this.connectionSettings = cloneDeep(config.connection || {})
  if (this.driverName && config.connection) {
    this.initializeDriver()
    if (!config.pool || (config.pool && config.pool.max !== 0)) {
      this.initializePool(config)
    }
  }
  this.valueForUndefined = this.raw('DEFAULT');
  if (config.useNullAsDefault) {
    this.valueForUndefined = null
  }
}
    function algoliasearch(applicationID, apiKey, opts) {
      var cloneDeep = require('lodash/lang/cloneDeep');

      var getDocumentProtocol = require('../get-document-protocol');

      opts = cloneDeep(opts || {});

      if (opts.protocol === undefined) {
        opts.protocol = getDocumentProtocol();
      }

      opts._ua = opts._ua || algoliasearch.ua;

      return new AlgoliaSearchAngular(applicationID, apiKey, opts);
    }
function algoliasearch(applicationID, apiKey, opts) {
  var cloneDeep = require('lodash/lang/cloneDeep');
  opts = cloneDeep(opts || {});

  if (opts.protocol === undefined) {
    opts.protocol = 'https:';
  }

  opts._setTimeout = _setTimeout;

  opts._ua = opts._ua || algoliasearch.ua;
  opts._useCache = false;

  return new AlgoliaSearchParse(applicationID, apiKey, opts);
}
  return function places(appID, apiKey, opts) {
    var cloneDeep = require('lodash/lang/cloneDeep');

    opts = opts && cloneDeep(opts) || {};
    opts.hosts = opts.hosts || [
      'places-dsn.algolia.net',
      'places-1.algolianet.com',
      'places-2.algolianet.com',
      'places-3.algolianet.com'
    ];

    var client = algoliasearch(appID, apiKey, opts);
    var index = client.initIndex('places');
    index.search = buildSearchMethod('query', '/1/places/query');
    return index;
  };
Example #27
0
  static clearHighlights(graph) {
    let newGraph = cloneDeep(graph);

    values(newGraph.nodes).forEach(node => {
      delete newGraph.nodes[node.id].display.status;
    });

    values(newGraph.edges).forEach(edge => {
      delete newGraph.edges[edge.id].display.status;
    });

    values(newGraph.captions).forEach(caption => {
      delete newGraph.captions[caption.id].display.status;
    });    

    return newGraph;
  }
Example #28
0
function compile(filename) {
  let result;

  let optsManager = new OptionManager;

  // merge in base options and resolve all the plugins and presets relative to this file
  optsManager.mergeOptions({
    options: deepClone(transformOpts),
    alias: "base",
    dirname: path.dirname(filename)
  });

  let opts = optsManager.init({ filename });

  let cacheKey = `${JSON.stringify(opts)}:${babel.version}`;

  let env = process.env.BABEL_ENV || process.env.NODE_ENV;
  if (env) cacheKey += `:${env}`;

  if (cache) {
    let cached = cache[cacheKey];
    if (cached && cached.mtime === mtime(filename)) {
      result = cached;
    }
  }

  if (!result) {
    result = babel.transformFileSync(filename, extend(opts, {
      // Do not process config files since has already been done with the OptionManager
      // calls above and would introduce duplicates.
      babelrc: false,
      sourceMap: "both",
      ast:       false
    }));
  }

  if (cache) {
    cache[cacheKey] = result;
    result.mtime = mtime(filename);
  }

  maps[filename] = result.map;

  return result.code;
}
Example #29
0
    return $scope.$on('$routeUpdate', (event) => {
      let valentEvent = event.$valentEvent;

      let params = this.parse();

      let diff = transform(params, (result, n, key) => {
        // TODO: use cached params instead of state
        let state = this[_state][key];

        if (!isEqual(n, state)) {
          result[key] = n;
        }
      });

      this[_state] = cloneDeep(params);

      callback(params, diff, valentEvent);
    });
  it('does not alter the initial options when rendering', () => {
    // Note: https://github.com/algolia/instantsearch.js/issues/1010
    // Make sure we work on a copy of the initial facetValues when rendering,
    // not directly editing it

    // Given
    const initialOptions = [{start: 0, end: 5, name: '1-5'}];
    const initialOptionsClone = cloneDeep(initialOptions);
    const testWidget = numericRefinementList({
      container,
      attributeName: 'price',
      options: initialOptions
    });

    // When
    testWidget.render({state, results, createURL});

    // Then
    expect(initialOptions).toEqual(initialOptionsClone);
  });