How to use auto-bind - 10 common examples

To help you get started, we’ve selected a few auto-bind 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 bentonam / fakeit / packages / fakeit-core / src / api.js View on Github external
seed: null,

        // fail after the first error
        fail_fast: true,
      },
      /* istanbul ignore next : to hard to test, also no reason to test for it */
      options || {},
    )

    this.config = new Config(this.settings)

    // this loads all the config files/plugins
    this._loadConfigs()

    // auto binds methods to it's instance
    autoBind(this)
  }
github terascope / teraslice / packages / teraslice-client-js / src / executions.ts View on Github external
constructor(config: ClientConfig) {
        super(config);
        // @ts-ignore
        autoBind(this);
    }
github dotansimha / graphql-code-generator / packages / plugins / other / visitor-plugin-common / src / base-resolvers-visitor.ts View on Github external
enumPrefix: getConfigValue(rawConfig.enumPrefix, true),
      federation: getConfigValue(rawConfig.federation, false),
      resolverTypeWrapperSignature: getConfigValue(rawConfig.resolverTypeWrapperSignature, 'Promise | T'),
      enumValues: parseEnumValues(_schema, rawConfig.enumValues),
      addUnderscoreToArgsType: getConfigValue(rawConfig.addUnderscoreToArgsType, false),
      contextType: parseMapper(rawConfig.contextType || 'any', 'ContextType'),
      fieldContextTypes: getConfigValue(rawConfig.fieldContextTypes, []),
      rootValueType: parseMapper(rawConfig.rootValueType || '{}', 'RootValueType'),
      avoidOptionals: getConfigValue(rawConfig.avoidOptionals, false),
      defaultMapper: rawConfig.defaultMapper ? parseMapper(rawConfig.defaultMapper || 'any', 'DefaultMapperType') : null,
      mappers: transformMappers(rawConfig.mappers || {}),
      scalars: buildScalars(_schema, rawConfig.scalars, defaultScalars),
      ...(additionalConfig || {}),
    } as TPluginConfig);

    autoBind(this);
    this._federation = new ApolloFederation({ enabled: this.config.federation, schema: this.schema });
    this._rootTypeNames = getRootTypeNames(_schema);
    this._variablesTransfomer = new OperationVariablesToObject(this.scalars, this.convertName);
    this._resolversTypes = this.createResolversFields(type => this.applyResolverTypeWrapper(type), type => this.clearResolverTypeWrapper(type), name => this.getTypeToUse(name));
    this._resolversParentTypes = this.createResolversFields(type => type, type => type, name => this.getParentTypeToUse(name));
    this._fieldContextTypeMap = this.createFieldContextTypeMap();
  }
github dotansimha / graphql-code-generator / packages / plugins / typescript / typescript / src / visitor.ts View on Github external
constructor(schema: GraphQLSchema, pluginConfig: TRawConfig, additionalConfig: Partial = {}) {
    super(schema, pluginConfig, {
      noExport: getConfigValue(pluginConfig.noExport, false),
      avoidOptionals: normalizeAvoidOptionals(getConfigValue(pluginConfig.avoidOptionals, false)),
      maybeValue: getConfigValue(pluginConfig.maybeValue, 'T | null'),
      constEnums: getConfigValue(pluginConfig.constEnums, false),
      enumsAsTypes: getConfigValue(pluginConfig.enumsAsTypes, false),
      immutableTypes: getConfigValue(pluginConfig.immutableTypes, false),
      ...(additionalConfig || {}),
    } as TParsedConfig);

    autoBind(this);
    const enumNames = Object.values(schema.getTypeMap())
      .map(type => (type instanceof GraphQLEnumType ? type.name : undefined))
      .filter(t => t);
    this.setArgumentsTransformer(new TypeScriptOperationVariablesToObject(this.scalars, this.convertName, this.config.avoidOptionals.object, this.config.immutableTypes, null, enumNames, pluginConfig.enumPrefix, this.config.enumValues));
    this.setDeclarationBlockConfig({
      enumNameValueSeparator: ' =',
      ignoreExport: this.config.noExport,
    });
  }
github dotansimha / graphql-code-generator / packages / plugins / flow / flow / src / visitor.ts View on Github external
constructor(schema: GraphQLSchema, pluginConfig: FlowPluginConfig) {
    super(schema, pluginConfig, {
      useFlowExactObjects: getConfigValue(pluginConfig.useFlowExactObjects, true),
      useFlowReadOnlyTypes: getConfigValue(pluginConfig.useFlowReadOnlyTypes, false),
    } as FlowPluginParsedConfig);
    autoBind(this);

    const enumNames = Object.values(schema.getTypeMap())
      .map(type => (type instanceof GraphQLEnumType ? type.name : undefined))
      .filter(t => t);
    this.setArgumentsTransformer(new FlowOperationVariablesToObject(this.scalars, this.convertName, null, enumNames, pluginConfig.enumPrefix));
    this.setDeclarationBlockConfig({
      blockWrapper: this.config.useFlowExactObjects ? '|' : '',
    });
  }
github adventurerscodex / adventurerscodex / src / charactersheet / viewmodels / character / stats / view.js View on Github external
constructor(params) {
        this.tabId = params.tabId;
        this.containerId = params.containerId;
        this.show = params.show;
        this.flip = params.flip;
        this.forceOuterCardResize = params.forceCardResize;

        this.health = ko.observable(new Health());
        this.massiveDamageTaken = ko.observable(false);
        this.deathSavesVisible = ko.observable(false);
        this.subscriptions = [];
        autoBind(this);
    }
github dotansimha / graphql-code-generator / packages / plugins / typescript / operations / src / visitor.ts View on Github external
constructor(schema: GraphQLSchema, config: TypeScriptDocumentsPluginConfig, allFragments: LoadedFragment[]) {
    super(
      config,
      {
        noExport: getConfigValue(config.noExport, false),
        avoidOptionals: typeof config.avoidOptionals === 'boolean' ? getConfigValue(config.avoidOptionals, false) : false,
        immutableTypes: getConfigValue(config.immutableTypes, false),
        nonOptionalTypename: getConfigValue(config.nonOptionalTypename, false),
      } as TypeScriptDocumentsParsedConfig,
      schema
    );

    autoBind(this);

    const clearOptional = (str: string): string => {
      const prefix = this.config.namespacedImportName ? `${this.config.namespacedImportName}\.` : '';
      const rgx = new RegExp(`^${prefix}Maybe<(.*?)>$`, 'is');

      if (str.startsWith(`${this.config.namespacedImportName ? `${this.config.namespacedImportName}.` : ''}Maybe`)) {
        return str.replace(rgx, '$1');
      }

      return str;
    };

    const wrapTypeWithModifiers = (baseType: string, type: GraphQLObjectType | GraphQLNonNull | GraphQLList): string => {
      const prefix = this.config.namespacedImportName ? `${this.config.namespacedImportName}.` : '';

      if (isNonNullType(type)) {
github adventurerscodex / adventurerscodex / src / charactersheet / viewmodels / character / spells / index.js View on Github external
constructor(params) {
        super(params);
        this.addFormId = '#add-spell';
        this.collapseAllId = '#spells-pane';

        this.filteredByCastable = ko.observable(false);
        this.spellStats = ko.observable(new SpellStats());
        this.spellSlots = ko.observableArray([]);
        autoBind(this);
    }
github giddyinc / doctopus / lib / SchemaBuilder.ts View on Github external
constructor(private _schema: Schema = {}) {
    autoBind(this);
  }

auto-bind

Automatically bind methods to their class instance

MIT
Latest version published 3 years ago

Package Health Score

70 / 100
Full package analysis

Popular auto-bind functions