How to use the when/keys.all function in when

To help you get started, we’ve selected a few when 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 natesilva / jayschema / lib / jayschema.js View on Github external
if (loaderErr) { return deferred.reject(loaderErr); }
    if (!this._schemaRegistry.isRegistered(ref)) { this.register(schema, ref); }
    deferred.resolve(schema);
  };

  // now request the missing refs that have not been requested yet
  for (var index = 0, len = missing.length; index !== len; ++index) {
    var ref = missing[index];
    var deferred = when.defer();
    this._refsRequested[SchemaRegistry._normalizeId(ref)] = deferred.promise;
    this.loader(ref, onLoaded.bind(this, ref, deferred));
  }

  // wait for all of them
  var self = this;
  keys.all(this._refsRequested).then(
    function() {
      // all promises fulfilled

      if (missing.length) {
        // We loaded some schemas. We need to recurse to load
        // additional schemas that were referenced by the schemas we
        // just loaded.
        self._loadMissingRefs(depth - 1, callback);
      } else {
        // We didn’t load any more schemas ourselves; we were just
        // waiting for any loader promises to be fulfilled.
        callback();
      }
    },
    callback  // one or more promises rejected
  );
github static-dev / spike-records / lib / index.js View on Github external
}

    // Here, we check to see if the user has provided a single-view template,
    // and if so, add its path to spike's ignores. This is because templates
    // render separately with special variables through this plugin and
    // shouldn't be processed as normal views by spike.
    const tpl = this.opts[k].template
    if (tpl && Object.keys(tpl).length) {
      spikeOpts.ignore.push(path.join(compiler.options.context, tpl.path))
    }
  }

  // Here's where the magic happens. First we use the when/keys utility to go
  // through our "tasks" object and resolve all the promises. More info here:
  // https://github.com/cujojs/when/blob/master/docs/api.md#whenkeys-all
  keys.all(tasks)
    // Then we go through each of they keys again, applying the user-provided
    // transform function to each one, if it exists.
    .then((tasks) => keys.map(tasks, transformData.bind(this)))
    // After this, we add the fully resolved and transformed data to the
    // addDataTo object, so it can be made available in views.
    .tap(mergeIntoLocals.bind(this))
    // Then we save the locals on a class property for templates to use. We will
    // need this in a later webpack hook when we're writing templates.
    .then((locals) => { this._locals = locals })
    // And finally, tell webpack we're done with our business here
    .done(() => { done() }, done)
}
github megamsys / varai / varai / actions / localfilesystem.js View on Github external
return nodeFn.call(fs.readdir, dir).then(function (contents) {
        contents.sort().forEach(function(fn) {
            var stats = fs.lstatSync(dir+"/"+fn);
            if (stats.isDirectory()) {
                dirCount += 1;
                dirs[fn] = listFiles(dir+"/"+fn)
            } else {
                files.push(fn.split(".")[0]);
            }
        })
        var result = {};
        if (dirCount > 0) { result.d = keys.all(dirs); }
        if (files.length > 0) { result.f = when.resolve(files); }
        return keys.all(result);
    })
}
github megamsys / varai / varai / actions / localfilesystem.js View on Github external
return nodeFn.call(fs.readdir, dir).then(function (contents) {
        contents.sort().forEach(function(fn) {
            var stats = fs.lstatSync(dir+"/"+fn);
            if (stats.isDirectory()) {
                dirCount += 1;
                dirs[fn] = listFiles(dir+"/"+fn)
            } else {
                files.push(fn.split(".")[0]);
            }
        })
        var result = {};
        if (dirCount > 0) { result.d = keys.all(dirs); }
        if (files.length > 0) { result.f = when.resolve(files); }
        return keys.all(result);
    })
}
github Xantier / nerd-stack / app / util / dataLoader.js View on Github external
export default (_token, routerState, _context) => {
  token = _token;
  context = _context || {};
  return all(routerState.routes.filter((route) => {
    return route.handler.load;
  }).reduce(function fillPromises(promises, route) {
    context.displayName = route.handler.displayName;
    context.token = token;
    promises[route.handler.displayName] = route.handler.load(context);
    return handleChildren(promises, route.handler.children);
  }, {}));
};
github reapp / reapp-ui / app / lib / run.js View on Github external
var fetchAllData = (routes, params) => {
    var promises = routes
      .filter(route => route.handler.fetchData)
      .reduce((promises, route) => {
        promises[route.name] = route.handler.fetchData(params);
        return promises;
      }, {});

    return ResolveAllPromises(promises);
  };
github ryanflorence / react-router-mega-demo / app / utils / fetchData.js View on Github external
var fetchData = module.exports = (token, routerState) => {
  var { params, query } = routerState;
  return all(routerState.routes.filter((route) => {
    return route.handler.fetchData;
  }).reduce((promises, route) => {
    promises[route.name] = route.handler.fetchData(token, params, query);
    return promises;
  }, {}));
};
github QubitProducts / cherrytree / examples / cherry-pick / app / app.js View on Github external
return when.all(transition.routes.map((route) => {
    if (route.RouteHandler.fetchData) {
      return keys.all(route.RouteHandler.fetchData(transition.params, transition))
    }
  }))
})
github QubitProducts / cherrytree / examples / cherry-pick / app / index.js View on Github external
var datas = when.all(transition.nextRoutes.map(function (route) {
    if (route.RouteHandler.fetchData) {
      return keys.all(route.RouteHandler.fetchData(transition.params, transition));
    }
  }));
  return datas;
github WEBdeBS / webdebs-links / src / utils / fetch-data.js View on Github external
export default (state) => {
  return all(state.routes.filter((route) => {
    return route.handler.fetchData;
  }).reduce((promises, route) => {
    promises[route.name] = route.handler.fetchData(state);
    return promises;
  }, {}));
};