lodash#differenceWith TypeScript Examples

The following examples show how to use lodash#differenceWith. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: merge-cell.ts    From S2 with MIT License 6 votes vote down vote up
differenceTempMergedCells = (
  mainTempMergedCells: TempMergedCell[],
  compareTempMergedCells: TempMergedCell[],
): TempMergedCell[] => {
  return differenceWith(
    mainTempMergedCells,
    compareTempMergedCells,
    (main, compare) => {
      return (
        isEqual(main.viewMeta.id, compare.viewMeta.id) &&
        !main.isPartiallyVisible
      );
    },
  );
}
Example #2
Source File: customOperators.ts    From webapp with MIT License 6 votes vote down vote up
distinctArrayItem =
  <T>(initialValue: T[], comparator?: (a: T, b: T) => boolean) =>
  (source: Observable<T[]>) =>
    source.pipe(
      scan(
        (acc, item) => {
          const difference = differenceWith(
            item,
            acc.allEmissions,
            comparator || isEqual
          );
          return {
            allEmissions: [...acc.allEmissions, ...difference],
            newData: difference
          };
        },
        { allEmissions: initialValue, newData: [] } as DataCache<T>
      ),
      filter(dataCache => dataCache.newData.length > 0),
      pluck("newData"),
      startWith(initialValue)
    )
Example #3
Source File: eosNetwork.ts    From webapp with MIT License 5 votes vote down vote up
@action async fetchBulkBalances(
    tokens: GetBalanceParam["tokens"]
  ): Promise<TokenBalanceReturn[]> {
    const currentUser = this.currentUser;
    const bulkBalances = await getTokenBalancesDfuse(currentUser).catch(
      () => [] as TokenBalanceReturn[]
    );

    const missingTokens = differenceWith(tokens, bulkBalances, compareToken);

    if (missingTokens.length == 0) return bulkBalances;

    let extraBalances: TokenBalanceReturn[] = [];
    try {
      const bulkRequested = await dfuseClient.stateTablesForAccounts<{
        balance: string;
      }>(
        missingTokens.map(x => x.contract),
        currentUser,
        "accounts"
      );
      const dfuseParsed = bulkRequested.tables
        .filter(table => table.rows.length > 0)
        .flatMap(table => ({
          contract: table.account,
          balance: table.rows[0].json!.balance
        }));
      extraBalances = dfuseParsed.map((json): TokenBalanceReturn => {
        const asset = new Asset(json.balance);
        return {
          balance: assetToDecNumberString(asset),
          contract: json.contract,
          symbol: asset.symbol.code().to_string(),
          precision: asset.symbol.precision()
        };
      });
    } catch (e) {}

    const missingTokensTwo = differenceWith(
      extraBalances,
      missingTokens,
      compareToken
    );

    const extraBalancesRpc = await this.getTokenBalancesRpc({
      tokens: missingTokensTwo,
      currentUser
    });

    return [...bulkBalances, ...extraBalances, ...extraBalancesRpc];
  }
Example #4
Source File: i18n-extract.ts    From erda-ui with GNU Affero General Public License v3.0 4 votes vote down vote up
function customFlush(done: () => void) {
  const enToZhWords: Obj = zhWordMap;
  // @ts-ignore api
  const { resStore } = this.parser;
  // @ts-ignore api
  const { resource, removeUnusedKeys, sort, defaultValue } = this.parser.options;

  Object.keys(resStore).forEach((lng) => {
    const namespaces = resStore[lng];
    // The untranslated English value and key are consistent
    if (lng === 'en') {
      Object.keys(namespaces).forEach((_ns) => {
        const obj = namespaces[_ns];
        Object.keys(obj).forEach((k) => {
          if (obj[k] === defaultValue) {
            obj[k] = k.replace('&#58;', ':');
          }
        });
      });
    }

    const filePath = resource.savePath.replace('{{lng}}', lng);
    let oldContent = lng === 'zh' ? originalZhJson : originalEnJson;

    // Remove obsolete keys
    if (removeUnusedKeys) {
      const namespaceKeys = flattenObjectKeys(namespaces);
      const oldContentKeys = flattenObjectKeys(oldContent);
      const unusedKeys = differenceWith(oldContentKeys, namespaceKeys, isEqual);

      for (let i = 0; i < unusedKeys.length; ++i) {
        unset(oldContent, unusedKeys[i]);
      }

      oldContent = omitEmptyObject(oldContent);
    }

    // combine old content
    let output = merge(namespaces, oldContent);
    if (sort) {
      output = sortObject(output);
    }

    // substitution zh locale
    if (lng === 'zh') {
      Object.keys(output).forEach((_ns) => {
        const obj = output[_ns];
        Object.keys(obj).forEach((k) => {
          if (obj[k] === defaultValue) {
            const zh = enToZhWords[k] || enToZhWords[`${_ns}:${k}`];
            if (zh) {
              obj[k] = zh;
            } else {
              logError(`there is untranslated content in zh.json: ${k}, please handle it manually`);
            }
          }
        });
      });
    }

    if (isExternal) {
      fs.writeFile(filePath, `${JSON.stringify(output, null, resource.jsonIndent)}\n`, 'utf8', (writeErr) => {
        if (writeErr) return logError(`writing failed:${lng}`, writeErr);
      });
    } else {
      const { default: defaultContent, ...restContent } = output;
      fs.writeFile(filePath, `${JSON.stringify(restContent, null, resource.jsonIndent)}\n`, 'utf8', (writeErr) => {
        if (writeErr) return logError(`writing failed:${lng}`, writeErr);
      });
      const defaultLocalePath = `${internalLocalePathMap.default}/${lng}.json`;

      fs.writeFile(
        defaultLocalePath,
        `${JSON.stringify({ default: defaultContent }, null, resource.jsonIndent)}\n`,
        'utf8',
        (writeErr) => {
          if (writeErr) return logError(`writing failed:${lng}`, writeErr);
        },
      );
    }
  });

  done();
}