How to use p-props - 9 common examples

To help you get started, we’ve selected a few p-props 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 Yoctol / bottender / packages / bottender / src / slack / SlackConnector.ts View on Github external
channelId
      );
    }

    // TODO: how to know if user leave team?
    // TODO: team info shared by all channels?
    if (
      !session.team ||
      (session.team.members &&
        Array.isArray(session.team.members) &&
        session.team.members.indexOf(senderId) < 0)
    ) {
      promises.allUsers = this._client.getAllUserList();
    }

    const results = await pProps(promises);

    // FIXME: refine user
    session.user = {
      id: senderId,
      _updatedAt: new Date().toISOString(),
      ...results.sender,
    };
    Object.freeze(session.user);
    Object.defineProperty(session, 'user', {
      configurable: false,
      enumerable: true,
      writable: false,
      value: session.user,
    });

    if (promises.channel) {
github xojs / atom-linter-xo / lib / lint.js View on Github external
export default function lint(editor) {
	const filename = editor.getPath();

	if (!filename) {
		return async () => EMPTY_REPORT;
	}

	const cwd = path.dirname(filename);

	const pendingContext = pProps({
		cwd: (async () => {
			const pkgPath = await getPackagePath(cwd);
			return pkgPath ? path.dirname(pkgPath) : cwd;
		})(),
		depends: dependsOnXO(cwd),
		xo: getXO(cwd)
	});

	// (source: string, options?: Object) => Promise
	return async (source, options) => {
		const {cwd, depends, xo} = await pendingContext;

		if (!depends) {
			return EMPTY_REPORT;
		}
github tinajs / mina-webpack / packages / mina-entry-webpack-plugin / src / loaders / virtual-mina-loader.ts View on Github external
this._module.type !== 'javascript/auto'
  ) {
    this._module.type = 'javascript/auto'
    this._module.generator = new JavascriptGenerator()
    this._module.parser = new JavascriptParser()
  }

  const done = this.async()!

  const options = loaderUtils.getOptions(this) || {
    extensions: {},
  }

  this.addContextDependency(dirname(this.resourcePath))

  pProps(options.extensions, (extnames: Array) => {
    let findFileWithExtname = (extname: string) => {
      let filePath = replaceExt(this.resourcePath, `.${extname}`)
      // @ts-ignore
      return fs.exists(filePath).then(isExist => ({ isExist, filePath }))
    }
    return pAny(extnames.map(findFileWithExtname), {
      filter: ({ isExist }) => isExist,
    }).then(
      ({ filePath }) => {
        this.addDependency(filePath)
        return fs.readFile(filePath, 'utf8')
      },
      () => {}
    )
  })
    .then((parts: Record) => done(null, template(parts)))
github wtgtybhertgeghgtwtg / env-and-files / src / loadConfig.js View on Github external
export default function loadConfig(
  configMap: CMap,
): Promise> {
  if (!isobject(configMap)) {
    return Promise.reject(new Error('"configMap" must be a ConfigMap object.'));
  }
  const errors = [];
  return pProps(configMap, (group, groupName) => {
    if (!isobject(group)) {
      return Promise.reject(
        new Error(`"configMap.${groupName}" must be a ConfigGroup object.`),
      );
    }
    return pProps(group, (prop, propName) =>
      loadProperty(prop, propName, groupName).then(({error, value}) => {
        if (error) {
          errors.push(error);
        }
        return value;
      }),
    );
  }).then(result => {
    if (errors.length > 0) {
      throw new ConfigError(errors);
github u-wave / core / src / controllers / booth.js View on Github external
export async function getBoothData(uw) {
  const { booth, redis } = uw;

  const historyEntry = await booth.getCurrentEntry();

  if (!historyEntry || !historyEntry.user) {
    return null;
  }

  await historyEntry.populate('media.media').execPopulate();

  const stats = await props({
    upvotes: redis.smembers('booth:upvotes'),
    downvotes: redis.smembers('booth:downvotes'),
    favorites: redis.smembers('booth:favorites'),
  });

  return {
    historyID: historyEntry.id,
    playlistID: `${historyEntry.playlist}`,
    playedAt: Date.parse(historyEntry.playedAt),
    userID: `${historyEntry.user}`,
    media: historyEntry.media,
    stats,
  };
}
export async function getBooth(req) {
github u-wave / core / src / plugins / avatars.js View on Github external
async getMagicAvatars(userID) {
    const { users } = this.uw;
    const user = await users.getUser(userID);

    const promises = new Map();
    this.magicAvatars.forEach((generator, name) => {
      promises.set(name, generator(user));
    });

    const avatars = await props(promises);

    return Array.from(avatars).map(([name, url]) => ({
      type: 'magic',
      name,
      url,
    })).filter(({ url }) => url != null);
  }
github StoDevX / AAO-React-Native / source / lib / course-search / load-filter-options.js View on Github external
export function loadAllCourseFilterOptions(): Promise {
	return pProps(
		mapValues(filterCategories, (category: FilterCategory) =>
			fetch(category.url).json(),
		),
	).then(result => result)
}
github wtgtybhertgeghgtwtg / env-and-files / src / loadConfig.js View on Github external
return pProps(configMap, (group, groupName) => {
    if (!isobject(group)) {
      return Promise.reject(
        new Error(`"configMap.${groupName}" must be a ConfigGroup object.`),
      );
    }
    return pProps(group, (prop, propName) =>
      loadProperty(prop, propName, groupName).then(({error, value}) => {
        if (error) {
          errors.push(error);
        }
        return value;
      }),
    );
  }).then(result => {
    if (errors.length > 0) {
github u-wave / core / src / plugins / booth.js View on Github external
async saveStats(entry) {
    const stats = await props({
      upvotes: this.uw.redis.smembers('booth:upvotes'),
      downvotes: this.uw.redis.smembers('booth:downvotes'),
      favorites: this.uw.redis.smembers('booth:favorites'),
    });

    Object.assign(entry, stats);
    return entry.save();
  }

p-props

Like `Promise.all()` but for `Map` and `Object`

MIT
Latest version published 1 year ago

Package Health Score

59 / 100
Full package analysis

Popular p-props functions