How to use the typescript-memoize.Memoize function in typescript-memoize

To help you get started, we’ve selected a few typescript-memoize 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 ConnextProject / indra / modules / cf-core / src / models / app-instance.ts View on Github external
@Memoize()
  public get identity(): AppIdentity {
    return {
      participants: this.participants,
      appDefinition: this.appInterface.addr,
      defaultTimeout: this.defaultTimeout,
      channelNonce: this.appSeqNo
    };
  }

  @Memoize()
  public get hashOfLatestState() {
    return keccak256(this.encodedLatestState);
  }

  @Memoize()
  // todo(xuanji): we should print better error messages here
  public get encodedLatestState() {
    return defaultAbiCoder.encode(
      [this.appInterface.stateEncoding],
      [this.latestState]
    );
  }

  @Memoize()
  public get encodedInterpreterParams() {
    if (!this.isVirtualApp) {
      switch (this.outcomeType) {
        case OutcomeType.SINGLE_ASSET_TWO_PARTY_COIN_TRANSFER: {
          return defaultAbiCoder.encode(
            [singleAssetTwoPartyCoinTransferInterpreterParamsEncoding],
            [this.singleAssetTwoPartyCoinTransferInterpreterParams]
github embroider-build / embroider / packages / compat / src / moved-package-cache.ts View on Github external
for (let [pkg, mustMove] of this.mustMove) {
      if (mustMove) {
        result.add(pkg);
      }
    }
    return result;
  }

  // the npm structure we're shadowing could have a dependency nearly anywhere
  // on disk. We want to maintain their relations to each other. So we must find
  // the point in the filesystem that contains all of them, which could even be
  // "/" (for example, if you npm-linked a dependency that lives in /tmp).
  //
  // The commonSegmentCount is how many leading path segments are shared by all
  // our packages.
  @Memoize()
  get commonSegmentCount(): number {
    return [...this.packages].reduce((longestPrefix, pkg) => {
      let candidate = pathSegments(pkg.root);
      let shorter, longer;
      if (longestPrefix.length > candidate.length) {
        shorter = candidate;
        longer = longestPrefix;
      } else {
        shorter = longestPrefix;
        longer = candidate;
      }
      let i = 0;
      for (; i < shorter.length; i++) {
        if (shorter[i] !== longer[i]) {
          break;
        }
github embroider-build / embroider / packages / compat / src / v1-app.ts View on Github external
index = mergeTrees([index, srcIndex], {
        overwrite: true,
        annotation: 'merge classic and MU index.html',
      });
    }

    let patterns = this.configReplacePatterns;

    return new this.configReplace(index, this.configTree, {
      configPath: join('environments', `${this.app.env}.json`),
      files: [indexFilePath],
      patterns,
    });
  }

  @Memoize()
  babelConfig(): TransformOptions {
    // this finds all the built-in babel configuration that comes with ember-cli-babel
    const babelAddon = (this.app.project as any).findAddonByName('ember-cli-babel');
    const babelConfig = babelAddon.buildBabelOptions({
      'ember-cli-babel': {
        includeExternalHelpers: true,
        compileModules: false,
        disableDebugTooling: false,
        disablePresetEnv: false,
        disableEmberModulesAPIPolyfill: false,
        disableDecoratorTransforms: false,
      },
    });

    let plugins = babelConfig.plugins as any[];
    let presets = babelConfig.presets;
github embroider-build / embroider / packages / compat / src / compat-adapters / ember-cli-clipboard.ts View on Github external
import V1Addon from '../v1-addon';
import { Memoize } from 'typescript-memoize';
import Funnel from 'broccoli-funnel';

export default class EmberCLIClipboard extends V1Addon {
  @Memoize()
  get v2Tree() {
    let tree = super.v2Tree;
    return new Funnel(tree, {
      // ember-cli-clipboard is wrapping *everything* in its vendor tree inside
      // a fastboot guard, including a package.json file. The presence a file
      // named "package.json" that isn't actually valid JSON makes packagers
      // like Webpack barf.
      exclude: ['vendor/clipboard/package.json'],
    });
  }
}
github embroider-build / embroider / packages / compat / src / v1-addon.ts View on Github external
// even if there are no custom babel plugins, if we need to do any
    // preprocessing of inline handlebars templates we still need to run the
    // custom babel.
    return this.needsInlineHBS();
  }

  get name(): string {
    return this.packageJSON.name;
  }

  protected get packageJSON() {
    return this.addonInstance.pkg;
  }

  @Memoize()
  get root(): string {
    // addonInstance.root gets modified by a customized "main" or
    // "ember-addon.main" in package.json. We want the real package root here
    // (the place where package.json lives).
    return dirname(pkgUpSync(this.addonInstance.root)!);
  }

  @Memoize()
  private get mainModule() {
    // eslint-disable-next-line @typescript-eslint/no-require-imports
    const mod = require(this.addonInstance.constructor._meta_.modulePath);

    if (typeof mod === 'function') {
      return mod.prototype;
    } else {
      return mod;
github cardstack / cardstack / packages / cli / pre-build.ts View on Github external
ui.writeInfoLine(`using temp dir ${this.workDir}`);
    ui.writeInfoLine(`destination is ${this.destDir}/blueprints`);
  }

  @Memoize()
  private get workDir(): string {
    let hash = createHash("md5");
    hash.update(
      this.destDir +
        "\0" +
        (process.env.CARDSTACK_DEV ? "nocache" : hashForDep(__dirname))
    );
    return join(tmpdir(), "cardstack", hash.digest("hex").slice(0, 6));
  }

  @Memoize()
  private get appDir(): string {
    return join(this.workDir, appName);
  }

  private exclude(filepath: string) {
    if (filepath.includes("node_modules")) {
      return false;
    } else if (filepath.includes(".cardstack-ready")) {
      return false;
    } else {
      return true;
    }
  }

  private copyToBlueprint() {
    let blueprintsDir = join(this.destDir, "blueprints");
github seagull-js / seagull / src / lib / shrimp.ts View on Github external
get _interface(): { [fieldName: string]: string } {
    const result = {}
    for (const key of Object.keys(this)) {
      const type = Reflect.getMetadata('design:type', this, key)
      if (type && type.name) {
        result[key] = type.name.toLowerCase()
      }
    }
    return result
  }

  /**
   * Get a list of fields from a derived shrimp. In other words: a list of
   * fields you defined in your shrimp subclass.
   */
  @Memoize()
  get _ownFields(): string[] {
    const whitelist = new Shrimp()
    return Object.keys(this._interface).filter(key => !(key in whitelist))
  }

  /**
   * Accessor for a list of current type errors. You can check at runtime
   * (whenever you want) if the current shrimp has any type errors and which
   * properties have the wrong type as value.
   * To only check if there is _any error at all_, use the convenient
   * [[_isValid]] accessor.
   */
  get _errors(): string[] {
    const itf = this._interface
    return this._ownFields
      .map(key => (typeof this[key] !== itf[key] ? key : false))
github cardstack / cardstack / packages / cli / pre-build.ts View on Github external
return builder.preBuild();
}

class PreBuilder {
  private destDir: string;
  private ui: UI;

  constructor({ dir, ui }: Options) {
    this.destDir = dir;
    this.ui = ui;
    ensureDirSync(this.workDir);
    ui.writeInfoLine(`using temp dir ${this.workDir}`);
    ui.writeInfoLine(`destination is ${this.destDir}/blueprints`);
  }

  @Memoize()
  private get workDir(): string {
    let hash = createHash("md5");
    hash.update(
      this.destDir +
        "\0" +
        (process.env.CARDSTACK_DEV ? "nocache" : hashForDep(__dirname))
    );
    return join(tmpdir(), "cardstack", hash.digest("hex").slice(0, 6));
  }

  @Memoize()
  private get appDir(): string {
    return join(this.workDir, appName);
  }

  private exclude(filepath: string) {
github embroider-build / embroider / packages / compat / src / v1-app.ts View on Github external
}

  @Memoize()
  get config(): V1Config {
    return new V1Config(this.configTree, this.app.env);
  }

  get autoRun(): boolean {
    return this.app.options.autoRun;
  }

  private get storeConfigInMeta(): boolean {
    return this.app.options.storeConfigInMeta;
  }

  @Memoize()
  private get configReplacePatterns() {
    return this.appUtils.configReplacePatterns({
      addons: this.app.project.addons,
      autoRun: this.autoRun,
      storeConfigInMeta: this.storeConfigInMeta,
      isModuleUnification: this.isModuleUnification,
    });
  }

  get htmlTree() {
    if (this.app.tests) {
      return mergeTrees([this.indexTree, this.app.testIndex()]);
    }
    {
      return this.indexTree;
    }
github embroider-build / embroider / packages / compat / src / v1-app.ts View on Github external
return this.requireFromEmberCLI('ember-cli-preprocess-registry/preprocessors');
  }

  get shouldBuildTests(): boolean {
    return this.app.tests || false;
  }

  private get configTree() {
    return new this.configLoader(dirname(this.app.project.configPath()), {
      env: this.app.env,
      tests: this.app.tests || false,
      project: this.app.project,
    });
  }

  @Memoize()
  get config(): V1Config {
    return new V1Config(this.configTree, this.app.env);
  }

  get autoRun(): boolean {
    return this.app.options.autoRun;
  }

  private get storeConfigInMeta(): boolean {
    return this.app.options.storeConfigInMeta;
  }

  @Memoize()
  private get configReplacePatterns() {
    return this.appUtils.configReplacePatterns({
      addons: this.app.project.addons,

typescript-memoize

Memoize decorator for Typescript

MIT
Latest version published 2 years ago

Package Health Score

53 / 100
Full package analysis

Popular typescript-memoize functions