How to use lazy - 10 common examples

To help you get started, we’ve selected a few lazy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vinz243 / cassette / src / server / models / Model.js View on Github external
let opts = Lazy(query).pick([
        'limit', 'offset', 'sort', 'direction'
      ]).value();

      if (!opts.limit || opts.limit > 500 || opts.limit < 1) {
        opts.limit = 500;
      }

      let sort = {};
      sort[opts.sort || 'name'] = opts.direction ?
        (opts.direction == 'asc' ? 1 : -1) : 1;

      let res = (await db.cfind(q).sort(sort).limit(opts.limit)
        .skip(opts.skip || 0).exec()).map(d => new model(d));

      res.query = Lazy(q).merge(opts).value();
      return res;
    }
    // for (let i in this.fields.filter(t => t.type == 'oneToOne')) {
github bnjjj / my-infra / app / services / ovh-request / ovh-request.service.ts View on Github external
.map(timestamp => {
        let reqBody = null;
        let headers = {};

        if (typeof(config.body) === 'object' && Object.keys(config.body).length > 0) {
          if (config.method === 'PUT' || config.method === 'POST') {
            // Escape unicode
            reqBody = JSON.stringify(config.body).replace(/[\u0080-\uFFFF]/g, function(m) {
              return '\\u' + ('0000' + m.charCodeAt(0).toString(16)).slice(-4);
            });
            headers['Content-Length'] = reqBody.length;
          } else {
            url += ('?' + querystring.stringify(_(config.body).filter((elm) => elm != null).value()));
            config.body = {};
          }
        }

        headers = Object.assign({}, {
          'X-Ovh-Consumer': this.opts.consumerKey,
          'X-Ovh-Signature': this.getHashedSignature(config.method || 'GET', this.urlRoot + url, Object.keys(config.body).length ? config.body : null, timestamp),
          'X-Ovh-Timestamp': timestamp,
          'X-Ovh-Application': this.opts.appKey
        }, headers);

        if (config.method === 'POST' || config.method === 'PUT') {
          headers['Content-Type'] = 'application/json';
        }

        return { headers: new Headers(headers) };
github orbitdb / orbit-db / src / list / OrbitList.js View on Github external
    let indices = Lazy(item.next).map((next) => Lazy(this._items).map((f) => f.hash).indexOf(next)) // Find the item's parent's indices
    const index = indices.length > 0 ? Math.max(indices.max() + 1, 0) : 0; // find the largest index (latest parent)
github rockstat / chwriter / src / clickhouse / sync.ts View on Github external
}
      const schemaCols = Object.assign(
        {},
        customCols
      );
      // don't handle abstract tables
      if (_options.abstract) continue;
      // creating table
      if (!exists) {
        const query = showCreateTable(table, schemaCols, _options);
        this.log.info(`Creating table ${table}: ${query}`);
        await this.client.execute(query);
      }
      // calculating difference and apply changes
      else {
        const currTableKeys = Lazy(currTable).keys();
        const appendCols = Lazy(schemaCols)
          .keys()
          .without(currTableKeys.toArray())
          .toArray();
        if (appendCols.length > 0) {
          this.log.info({
            new_cols: appendCols.join(', ')
          }, `Altering table ${table}`);
          const query = showAlterTable(
            table,
            Lazy(schemaCols)
              .pick(appendCols)
              .toObject(),
            _options
          );
          await this.client.execute(query);
github orbitdb / ipfs-log / lib / log.js View on Github external
_insert(node) {
    let indices = Lazy(node.next).map((next) => Lazy(this._items).map((f) => f.hash).indexOf(next)) // Find the item's parent's indices
    const index = indices.toArray().length > 0 ? Math.max(indices.max() + 1, 0) : 0; // find the largest index (latest parent)
    this._items.splice(index, 0, node);
    return node;
  }
github rockstat / chwriter / src / clickhouse / sync.ts View on Github external
await this.client.execute(query);
      }
      // calculating difference and apply changes
      else {
        const currTableKeys = Lazy(currTable).keys();
        const appendCols = Lazy(schemaCols)
          .keys()
          .without(currTableKeys.toArray())
          .toArray();
        if (appendCols.length > 0) {
          this.log.info({
            new_cols: appendCols.join(', ')
          }, `Altering table ${table}`);
          const query = showAlterTable(
            table,
            Lazy(schemaCols)
              .pick(appendCols)
              .toObject(),
            _options
          );
          await this.client.execute(query);
        }
      }
    }
    // rediscover db structure
    await this.discover();
    this.log.info('Schema sync done');
  }
github persvr / pintura / lib / store / sql.js View on Github external
executeQuery: function(sql, options){
			// executes a query with provide start and end parameters, calculating the total number of rows
			if(options){
				if(typeof options.start === "number"){
					var countSql = sql.replace(/select.*?from/i,"SELECT COUNT(*) as count FROM");
					if(typeof options.end === "number"){
						sql += " LIMIT " + (options.end - options.start + 1);
					}
					sql += " OFFSET " + options.start;
					var results = this.executeSql(sql, options.parameters).rows;
					var lengthObject = first(this.executeSql(countSql, options.parameters).rows);
					
					results.totalCount = lengthObject.count;
					return results; 
				}
			}
			var results = this.executeSql(sql, options.parameters).rows;
			results.totalCount = results.length;
			return results; 			
		},
		getSchema: function(){
github slap-editor / slap / lib / ui / BaseElement.js View on Github external
BaseElement.prototype._initHandlers = function () {
  var self = this;
  self.on('focus', function () {
    logger.debug('focus', util.typeOf(self));
    if (!self.focusable) self.focusNext();
  });
  self.on('blur', function () { logger.debug('blur', util.typeOf(self)); });
  self.on('show', function () { self.setFront(); });
  self.on('keypress', _.noop); // 'element keypress' doesn't work correctly without this
  self.on('element keypress', function (el, ch, key) {
    switch (util.getBinding(self.options.bindings, key)) {
      case 'hide': self.hide(); return false;
      case 'focusNext': self.focusNext(); return false;
      case 'focusPrev': self.focusPrev(); return false;
    }
  });
};
github slap-editor / slap / lib / ui / BaseModal.js View on Github external
.filter(function (child) { return child instanceof BaseModal; })
    .without(self);

  self.on('element blur', function () {
    if (!self.screen.focused.hasAncestor(self) && self.screen.focused !== self) self.hide();
  });

  self.on('click', function () {
    process.nextTick(function () {
      // TODO: don't change focus if contained element has focus already
      var firstChild = self.children[0];
      if (firstChild) firstChild.focus();
    });
  });

  self.on('keypress', _.noop); // 'element keypress' doesn't work correctly without this
  self.on('element keypress', function (el, ch, key) {
    switch (util.getBinding(self.options.bindings, key)) {
      case 'hide': self.hide(); break;
      case 'focusNext': self.focusEl(1); break;
      case 'focusPrev': self.focusEl(-1); break;
    }
  });
  self.on('show', function () {
    self.otherModals.invoke('hide');
    // if (self.otherModals.pluck('visible').compact().none()) self.screen.saveFocus();
    process.nextTick(function () { self.parent.render(); });
  });
  self.on('hide', function () {
    if (self.otherModals.pluck('visible').compact().none()) {
      self.parent.lockKeys = true; process.nextTick(function () { self.parent.lockKeys = false; }); // FIXME: ugly hack to stop enter from last event from propagating to editor
github persvr / pintura / lib / facet.js View on Github external
return when(source, function(source){
			if(!source){
				throw new DatabaseError(3, "not found");
			}
			if(source instanceof Array){
				// this handles query results, but probably should create a branch for real arrays 
				var results = extendSome({
					some: function(callback){
						source.some(function(item){
							callback((item && typeof item == "object" && wrap(item, transaction, item, true)) || item);
						});
					},
					length: source.length,
				});
				results.totalCount = source.totalCount;
				return results;
			}		
			var instancePrototype = Object.create(facetPrototype);
			defineProperties(instancePrototype, {
				load: {
					value: function(){
						if(facetSchema.allowed && !facetSchema.allowed(transaction.env, source)){
							throw new AccessError("Access denied to " + source);

lazy

Lazy lists for node

MIT
Latest version published 12 years ago

Package Health Score

67 / 100
Full package analysis