emberjs-addons / ember-touch

A lightweight library for building and using touch gestures with Ember Applications
MIT License
182 stars 28 forks source link

Error with Ember master #17

Open mrship opened 11 years ago

mrship commented 11 years ago

I'm trying to use ember-touch with the latest master and I'm getting the error Uncaught TypeError: Cannot call method 'lookup' of undefined which is coming from:

  _createGestureManager: function() {
    var eventManager = get(this, 'eventManager');
    if (!eventManager) {
      var applicationGestureManager = get(this, 'container').lookup('gesture:application');

Can you advise why this doesn't work with the latest Ember API?

ppcano commented 11 years ago

I think, you are not using the router, aren't you?

With the current implementation, you have to pass the application container to the view, which is something done automatically when using ember-routing.

    var view = App.LandingScreenView.create({
      container: App.__container__
    });

I will figure out soon how this case can work easily.

mrship commented 11 years ago

I am using the router. I think it may have something to do with using a ContainerView with a currentViewBinding, e.g:

{{view Ember.ContainerView currentViewBinding="controller.myView"}}

I'm using the latest Ember master to resolve an issue with currentViewBinding in RC3.

If I remove my ContainerView with a currentViewBinding then ember-touch works.

Sorry I can't be more help, but I'm unsure why/how currentViewBinding is causing the problem

mrship commented 11 years ago

Also, if I pass the container to the controller.myView when I create it as you suggested, then ember-touch no longer throws an error. Graçias!

mrship commented 11 years ago

My apologies, but I'm wrong (again). It isn't anything to do with a ContainerView and I don't have ember-touch working. So, to revert to my original comment, I am using the router - I've got a fairly standard Ember app - and I can't get ember-touch to work due to the error thrown in the original report.

ppcano commented 11 years ago

The exception is thrown because your view has not setup the container, loot at how the view is extended here.

So,if you setup the container as I shown below or find any fix to setup the container on view creation, it must work.

I thought the view was configured with the container in the view creation.

Let me know, if you find a easy way to solve it. Anyway, I will take a look tomorrow using latest master, I think, maybe a last change has made the ember-touch setup not work anymore.

mrship commented 11 years ago

I'll try and find a workaround, but I ran your integration tests against the master I have (before the move to Handlebars RC4 from yesterday) and they failed with the same error, so it looks like something has changed in how a container is setup for a view.

Died on test #1     at eval (ember-touch/~tests/acceptance_tests/multiple_gestures:28:1)
    at eval (ember-touch/~tests/acceptance_tests/multiple_gestures:290:3)
    at eval (native)
    at http://localhost:9292/tests/minispade.js:17:31
    at Object.minispade.globalEval (http://localhost:9292/tests/minispade.js:18:14)
    at Object.minispade.require (http://localhost:9292/tests/minispade.js:31:20)
    at http://localhost:9292/tests/index.html?package=ember-touch:145:25: Cannot call method 'lookup' of undefined
Source:     
TypeError: Cannot call method 'lookup' of undefined
    at Em.View.reopen._createGestureManager (ember-touch/system/view_ext:33:62)
    at Em.View.reopen.init (ember-touch/system/view_ext:19:10)
    at superWrapper [as init] (ember:1051:16)
    at new Class (ember:10996:15)
    at Function.Mixin.create.create (ember:11294:12)
    at Object.numStart (ember-touch/~tests/acceptance_tests/multiple_gestures:30:22)
    at Object.Test.run (http://localhost:9292/tests/qunit/qunit-1.11.0.js:190:18)
    at http://localhost:9292/tests/qunit/qunit-1.11.0.js:348:10
    at process (http://localhost:9292/tests/qunit/qunit-1.11.0.js:1420:24)
    at http://localhost:9292/tests/qunit/qunit-1.11.0.js:466:5
ppcano commented 11 years ago

Thanks for the info. I will look at it soon and try to find a more convenient way to setup.

Meanwhile, does your configuration work for your case?

mrship commented 11 years ago

No, I can't get ember-touch to work at all with the latest ember master. See PR #18 for the changes to run the integration tests against the latest master.

mrship commented 11 years ago

OK, having investigated it further I have a series of commits that get it to work for me within a real project. Unfortunately though it breaks the test suite as we now need a controller as well as a view because the container comes from:

this.view.get('controller.container')

In addition, I've altered the creation of the applicationGestureManager to happen in #willInsertElement of the Ember.View rather than #init, e.g:

  willInsertElement: function() {
    this._super();
    this._createGestureManager();   
  },

  _createGestureManager: function() {  
    var eventManager = get(this, 'eventManager');
    if (!eventManager) {
      var applicationGestureManager = get(this, 'controller.container').lookup('gesture:application');

Doing the call in #willInsertElement means that we actually have a controller to get the container from.

My changes are in PR #19 so you can review in more detail.

mavilein commented 11 years ago

Today i also stumpled upon this error:

Uncaught TypeError: Cannot call method 'lookup' of undefined

I faced this problem too, when using ContainerViews. But i do not think that refering to the controller and usings its container is the right way to go. The answer to this problem is to let the framework handle the view creation. Before the fix my code looked like this:

var cinemasView = App.CinemasView.create({
    heading : heading
});

So did call create myself. But this not let Ember handle the creation and inject the needed container into the view. Instead i changed those lines to the following:

var cinemasView = this.createChildView(App.CinemasView, {
    heading : heading
});

The method above is provided by Ember.ContainerView. Using this method ensures that the property containerView is set on your new View.

@mrship : I think this would be a better approach to your problem. From my perspective it looks awkward, that your controller is responsible for creating a view. This is actually the source of your problem, i think. You should move your logic concerning myView to your ContainerView and use createChildView.