Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lucid defineHooks problem #94

Closed
bitkidd opened this issue Feb 1, 2017 · 0 comments
Closed

Lucid defineHooks problem #94

bitkidd opened this issue Feb 1, 2017 · 0 comments

Comments

@bitkidd
Copy link
Contributor

bitkidd commented Feb 1, 2017

Hello!
There is a method defineHooks, that causes some strange problems. For example, I have a model Icon:

class Icon extends Lucid {

  // boot
  static boot () {
    super.boot()
    this.defineHooks('beforeCreate', ['Icon.setDefaults', 'Icon.processImage'])
  }

}

And two hooks down there:

Icon.setDefaults = function * (next) {
  console.log('SET_DEFAULTS')
  yield next
}

Icon.processImage = function * (next) {
  console.log('PROCESS_IMAGE')
  yield next
}

So in this situation I receive an error E_INVALID_IOC_BINDING: Handler must point to a valid namespace or a closure, If I use just addHook one by one, everything works just fine.
So I decided to find the code that works inside that method and changed it from:

static defineHooks () {
  this.$modelHooks = {}
  const args = _.toArray(arguments)
  const type = args[0]
  const hooks = _.tail(args)
  _.each(hooks, (hook) => {
    this.addHook(type, hook)
  })
}

to

static defineHooks (type, hooks) {
  _.each(hooks, (hook) => {
    this.addHook(type, hook)
  })
}

After changes all works just fine. So the main question is, why is that method so complicated, as soon as its aim is just to iterate through an array of methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant