Example #1
0
export function registerLinters(ctx: ExtensionContext) {
	const globalConfig = getGlobalLintConfig();
	const linters = new LintCollection(globalConfig, vscode.workspace.getConfiguration("ruby").lint, vscode.workspace.rootPath);
	ctx.subscriptions.push(linters);

	function executeLinting(e: vscode.TextEditor | vscode.TextDocumentChangeEvent) {
		if (!e) return;
		linters.run(e.document);
	}

	// Debounce linting to prevent running on every keypress, only run when typing has stopped
	const lintDebounceTime = vscode.workspace.getConfiguration('ruby').lintDebounceTime;
	const executeDebouncedLinting = debounce(executeLinting, lintDebounceTime);

	ctx.subscriptions.push(vscode.window.onDidChangeActiveTextEditor(executeLinting));
	ctx.subscriptions.push(vscode.workspace.onDidChangeTextDocument(executeDebouncedLinting));
	ctx.subscriptions.push(vscode.workspace.onDidChangeConfiguration(() => {
		const docs = vscode.window.visibleTextEditors.map(editor => editor.document);
		console.log("Config changed. Should lint:", docs.length);
		const globalConfig = getGlobalLintConfig();
		linters.cfg(vscode.workspace.getConfiguration("ruby").lint, globalConfig);
		docs.forEach(doc => linters.run(doc));
	}));

	// run against all of the current open files
	vscode.window.visibleTextEditors.forEach(executeLinting);
}
Example #2
0
function initPicker(container, category, subCategory) {

  // should probably be disabled after optimizely test is over
  var vipFlag = location.search.match(/vip=true/) ? true : undefined

  const setCart = debounce(choices => {

    defer(() => document.querySelector('.checkout').classList.add('disabled', 'loading'))

    let refId

    try {
      refId = sessionStorage.getItem('refId')
    } catch (e) { /* nothing */ }

    fetch(`${host}/add-to-cart`, {
      headers: new Headers({'Content-Type': 'application/json'}),
      body: JSON.stringify({...choices, refId, cartId: activeCart && activeCart._id}),
      method: 'POST',
    })
      .then(res => {
        if (res.status < 399) {
          return res.json()
        } else {
          if (res.status === 400) {
            return res.json()
          }
          throw new Error('failed to add products to cart. choices: ' + JSON.stringify(choices))
        }
      })
      .then(cart => {

        if (cart.message && cart.sku) {
          // this is an error condition
          window.mdChooser.removeDeprecated(cart.sku);
          return;
        }

        setCartLink(cart._id)

        if (cart.bundles[0].skus.length) {
          document.querySelector('.checkout').classList.remove('disabled', 'loading')
        } else {
          document.querySelector('.checkout').classList.remove('loading')
        }

        store.setItem('cartId', cart._id)
        activeCart = cart
      })
      .catch(error => {
        activeCart = null
        store.setItem('cartId', '')
        return showError(error) // show error or something
      })
  }, 800, {leading: true, trailing: true}) // debounce options

  let preselected = activeCart ? activeCart.bundles[0].skus : []
  const isVip = activeCart ? activeCart.bundles[0].isVip : false
  const brand = location.hostname.match(/(localhost|foundation)/) ? 'foundation' : 'mrdavis'

  // we might have come here from an ad that pre-builds packs

  if (['mrdavis.com', 'staging-mrdavis.kinsta.com'].includes(location.hostname)) {
    try {
      let counter = 1
      const skusFromAd = []
      const paramsToRemove = []
      while (getQueryParam(`item${counter}`)) {
        const sku = getQueryParam(`item${counter}`)
        const product = window.stock.find(item => sku === item.sku)
        skusFromAd.push({...product, quantity: 1})
        paramsToRemove.push(`item${counter}`)
        counter++
      }

      if (skusFromAd.length > 0) {
        preselected = skusFromAd
        const urlWithoutParams = removeParamsFromSearch(paramsToRemove)
        // change the url to remove the ad params
        const url = `${location.protocol}//${location.hostname}${location.pathname}${urlWithoutParams.slice(0, -1)}${location.hash}`
        window.history.pushState({}, document.title, url)
        window.woopra.track('preselected-picker-init', {
          skus: preselected,
          numItems: preselected.length
        })
      }
    } catch (e) {
      console.error(e)
    }
  }

  window.mdChooser = new Chooser({
    brand,
    category,
    subCategory,
    preselected,
    pickerOpen: preselected.length === 0,
    params: {id: 'infinite', continuing: 0, isVip},
    el: container,
    priceAsVip: vipFlag,
    complete: function () {
      beginCheckout(activeCart)
    },
    itemSelected: function (product, skus, selected) {

      setCart(selected)

      if (window.woopra) {
        window.woopra.track('init-picker', {
          type: 'infinite',
          category: category,
          sku: product.sku
        })
      }
    },

    itemRemoved: (skus, choices) => {
      setCart(choices)
    },

    vipUpdated: function (choices) {
      setCart(choices)
    },

    afterRender: function (skus) {
      const chooser = document.getElementById('chooser')
      const checkout = chooser.querySelector('.checkout') as HTMLElement
      try {
        checkout.style.fontSize = '24px'
      } catch (e) {}
    }
  })
}
Example #3
0
 return function (target: any, name: string, descriptor: PropertyDescriptor) {
   descriptor.value = _debounced(descriptor.value, wait, option);
 }