fabrix icon indicating copy to clipboard operation
fabrix copied to clipboard

bug(): catch spools declarations that are not classes

Open scott-wyatt opened this issue 7 years ago • 0 comments

Attached is a possible script implementation to check if a spool is actually a class. This helps pure JS users more than TS users, but, since it all runs in JavaScript at the end of the day, it makes sense to do an explicit check.

export default fn => {
  if (typeof fn != "function") {
    return false
  }

  let proxy = new Proxy(fn, {
    construct: () => fn,
  })

  try {
    new proxy
  } catch {
    return false
  }

  return true
}

Additionally, with babel constructing things down to es5 for browsers, it would be helpful to detect if the spool is es5 or es6 already.

scott-wyatt avatar Jan 23 '19 03:01 scott-wyatt