How to use memoizee - 10 common examples

To help you get started, we’ve selected a few memoizee 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 AugurProject / augur / src / modules / link / selectors / links.js View on Github external
onLoad: () => {
    const abcContext = selectABCUIContext().abcContext;
    const usernames = abcContext.listUsernames();
    if (usernames.length > 0) {
      selectABCUIContext().openLoginWindow((result, airbitzAccount) => {
        if (airbitzAccount) {
          dispatch(loginWithAirbitz(airbitzAccount));
        } else {
          console.log('error registering in: ' + result);
        }
      });
    }
  }
}), { max: 1 });

export const selectMarketsLink = memoize((keywords, selectedFilterSort, selectedPageNum, subSet, selectedTopic, dispatch) => {
  const params = {};

  // page
  params.page = MARKETS;

  // search
  if (keywords != null && keywords.length > 0) {
    params[SEARCH_PARAM_NAME] = keywords;
  }

  // filter + sort
  if (selectedFilterSort.type !== FILTER_SORT_TYPE) {
    params[FILTER_SORT_TYPE_PARAM_NAME] = `${selectedFilterSort.type}`;
  }
  if (selectedFilterSort.sort !== FILTER_SORT_SORT) {
    params[FILTER_SORT_SORT_PARAM_NAME] = `${selectedFilterSort.sort}`;
github AugurProject / augur / src / modules / link / selectors / links.js View on Github external
myMarketsLink: selectMyMarketsLink(store.dispatch),
    myReportsLink: selectMyReportsLink(store.dispatch),
    topicsLink: selectTopicsLink(store.dispatch)
  };
  // NOTE -- pagination links are a special case.  Reference the pagination selector for how those work.
}

export const selectAccountLink = memoize((dispatch) => {
  const href = makeLocation({ page: ACCOUNT }).url;
  return {
    href,
    onClick: () => dispatch(updateURL(href))
  };
}, { max: 1 });

export const selectPreviousLink = memoize((dispatch) => {
  const href = makeLocation({ page: MARKETS }).url;
  return {
    href,
    onClick: () => dispatch(updateURL(href))
  };
}, { max: 1 });

export const selectAuthLink = memoize((authType, alsoLogout, dispatch) => {
  const determineLocation = () => makeLocation({ page: AUTHENTICATION }).url;

  const href = determineLocation();

  return {
    href,
    onClick: () => {
      dispatch(updateURL(href));
github polkadot-js / api / packages / rpc-core / src / index.ts View on Github external
// eslint-disable-next-line @typescript-eslint/no-use-before-define
          memoized.delete(...values);

          // Unsubscribe from provider
          subscriptionPromise
            .then((subscriptionId): Promise =>
              isNumber(subscriptionId)
                ? this.provider.unsubscribe(subType, unsubName, subscriptionId)
                : Promise.resolve(false)
            )
            .catch((error: Error): void => l.error(createErrorMessage(method, error)));
        };
      }).pipe(drr());
    };

    const memoized = memoizee(call, {
      // Dynamic length for argument
      length: false,
      // Normalize args so that different args that should be cached
      // together are cached together.
      // E.g.: `query.my.method('abc') === query.my.method(createType('AccountId', 'abc'));`
      // eslint-disable-next-line @typescript-eslint/unbound-method
      normalizer: JSON.stringify
    });

    return memoized;
  }
github AugurProject / augur-ui / src / modules / markets / helpers / order-and-assign-cumulative-shares.js View on Github external
openOrders[key].fullPrecisionPrice === price.fullPrecision
    );
    let total = createBigNumber(0);
    for (let i = 0; i < accountOrdersInPrice.length; i++) {
      if (openOrders[accountOrdersInPrice[i]]) {
        total = total.plus(
          openOrders[accountOrdersInPrice[i]].fullPrecisionAmount
        );
      }
    }
    return total.eq(ZERO) ? null : formatEther(total);
  }
  return null;
}

const orderAndAssignCumulativeShares = memoize(
  (orderBook, userOpenOrders, loginAccount) => {
    const rawBids = ((orderBook || {})[BIDS] || []).slice();
    const bids = rawBids.sort((a, b) => b.price.value - a.price.value).reduce(
      (p, order, i, orders) => [
        ...p,
        {
          price: order.price,
          shares: order.shares,
          cumulativeShares:
            p[i - 1] != null
              ? p[i - 1].cumulativeShares.plus(order.shares.fullPrecision)
              : createBigNumber(order.shares.fullPrecision),
          mySize: userOpenOrders
            ? calculateMySize(userOpenOrders.buy, loginAccount, order.price)
            : order.shares // use shares for creating market
        }
github hiendv / hireable / src / Cache.js View on Github external
rememberFunction (fn) {
    if (!this.options.maxAge) {
      // Disabled
      return fn
    }

    return MemoizeeInstance.call(this, fn, this.options)
  }
}
github AugurProject / augur / src / modules / orders / selectors / user-open-orders.js View on Github external
) {
  const { loginAccount } = store.getState();
  if (!loginAccount.address || marketOrderBook == null) return [];

  return userOpenOrders(
    marketId,
    outcomeId,
    loginAccount,
    marketOrderBook,
    orderCancellation,
    marketDescription,
    name
  );
}

const userOpenOrders = memoize(
  (
    marketId,
    outcomeId,
    loginAccount,
    marketOrderBook,
    orderCancellation,
    marketDescription,
    name
  ) => {
    const orderData = marketOrderBook[outcomeId];

    const userBids =
      orderData == null || orderData.buy == null
        ? []
        : getUserOpenOrders(
            marketId,
github NCI-GDC / portal-ui / src / packages / @ncigdc / utils / survivalplot.js View on Github external
time: d.time / DAYS_IN_YEAR,
        })),
      })),
    }
    : { results: [] };

  performanceTracker.end('survival:fetch', {
    filters: params.filters,
    data_sets: data.results.length,
    donors: sum(data.results.map(x => x.donors.length)),
  });

  return data;
}

export const getDefaultCurve = memoize(
  async ({ currentFilters, size, slug }: TPropsDefault): Promise => {
    const rawData = await fetchCurves(
      Array.isArray(currentFilters)
        ? currentFilters
        : currentFilters && [currentFilters],
      size
    );
    const hasEnoughData = enoughData(rawData);

    const legend = hasEnoughData
      ? slug && [
        {
          key: slug,
          value: `${rawData.results[0].donors.length.toLocaleString()} Cases with Survival Data`,
        },
      ]
github AugurProject / augur / src / modules / link / selectors / links.js View on Github external
dispatch(updateURL(href));
    }
  };
}, { max: 1 });

export const selectMyReportsLink = memoize((dispatch) => {
  const href = makeLocation({ page: MY_REPORTS }).url;
  return {
    href,
    onClick: () => {
      dispatch(updateURL(href));
    }
  };
}, { max: 1 });

export const selectTopicsLink = memoize((dispatch) => {
  const href = makeLocation({}).url;
  return {
    href,
    onClick: () => {
      dispatch(updateURL(href));
    }
  };
}, { max: 1 });

export const selectTopicLink = memoize((topic, dispatch) => {
  const href = makeLocation({
    page: MARKETS,
    [TOPIC_PARAM_NAME]: topic
  }).url;

  return {
github AugurProject / augur / src / modules / link / selectors / links.js View on Github external
const href = makeLocation({ page: ACCOUNT }).url;
  return {
    href,
    onClick: () => dispatch(updateURL(href))
  };
}, { max: 1 });

export const selectPreviousLink = memoize((dispatch) => {
  const href = makeLocation({ page: MARKETS }).url;
  return {
    href,
    onClick: () => dispatch(updateURL(href))
  };
}, { max: 1 });

export const selectAuthLink = memoize((authType, alsoLogout, dispatch) => {
  const determineLocation = () => makeLocation({ page: AUTHENTICATION }).url;

  const href = determineLocation();

  return {
    href,
    onClick: () => {
      dispatch(updateURL(href));

      if (alsoLogout) {
        dispatch(logout());
      }
    }
  };
}, { max: 1 });
github AugurProject / augur / packages / augur-ui / src / modules / portfolio / containers / positions.ts View on Github external
const mapStateToProps = (state) => {
  const positions = getLoginAccountPositions();
  const timestamps = getMarketsPositionsRecentlyTraded();
  const markets = getPositionsMarkets(timestamps, positions);

  return {
    markets,
  };
};

const mapDispatchToProps = (dispatch) => ({
  claimTradingProceeds: (marketId) =>
    dispatch(updateModal({ type: MODAL_CLAIM_TRADING_PROCEEDS, marketId })),
});

const getPositionsMarkets = memoize(
  (marketsPositionsRecentlyTraded, positions) =>
    Array.from(new Set([...positions.markets])).map((m) => ({
      ...m,
      recentlyTraded: marketsPositionsRecentlyTraded[m.id],
    })),
  { max: 1 },
);

const PositionsContainer = connect(
  mapStateToProps,
  mapDispatchToProps,
)(Positions);

export default PositionsContainer;

memoizee

Memoize/cache function results

ISC
Latest version published 7 months ago

Package Health Score

78 / 100
Full package analysis

Popular memoizee functions