# Help me to see whether it is a bug in RC-6?

**URL:** https://discuss.emberjs.com/t/help-me-to-see-whether-it-is-a-bug-in-rc-6/1628
**Category:** Uncategorized
**Created:** [June 26, 2013, 5:14am UTC](https://discuss.emberjs.com/t/help-me-to-see-whether-it-is-a-bug-in-rc-6/1628 "2013-06-26T05:14:22Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![nightire](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/nightire/32/14788_2.png) [@nightire](https://discuss.emberjs.com/u/nightire)
#### Post date: [June 26, 2013, 5:14am UTC](https://discuss.emberjs.com/t/help-me-to-see-whether-it-is-a-bug-in-rc-6/1628/1 "2013-06-26T05:14:22Z")

</div>

Suppose I have a `View` and a `Controller` like this:

```javascript
App.MyController = Ember.Controller.extend({
  activity: false,

  activate: function() {
    if (!(this.get('activity'))) { // if 'activity' is false, make it true
      this.toggleProperty('activity')
    }
  }
});

App.MyView = Ember.view.extend
  classNameBindings: ['isShown:active:'],
  isShown: false,

  show: function() { // toggle 'isShown' when 'controller.activity' changes
    this.toggleProperty('isShown')
  }.observes('controller.activity'),

  hide: function() { // when 'isShown' is true, we can turn off 'controller.activity'
    if (this.get('isShown')) {
      this.toggleProperty('controller.activity')
    }
  }

```

This works in RC-5 very well, `controller.activity` and `view.isShown` are `false` when application initialized, but when I upgrade to RC-6, `view.isShown` will automatically turns to `true` when application initialized, then it breaks everything related.

Anyone can explain me why `view.isShown` will be `true` by default? It doesn’t make sense to me. I’m sure nothing trigger the `activate` method when app is initializing, and I double checked these two properties:

```javascript
didInsertElement: function() {
  console.log(this.get('isShown')) // true!!! - why?
  console.log(this.get('controller.activity')) // false
}

```

I can make a little tweak to make it work as I wish, but still don’t understand why it is different between RC-5 and RC-6, is it a BUG or some internal changes?

BTW, I’ve checked the CHANGELOG, but no luck with this issue.

---

<div class="post-metadata">

### Author: ![jgwhite](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jgwhite/32/3678_2.png) [@jgwhite](https://discuss.emberjs.com/u/jgwhite)
#### Post date: [June 26, 2013, 7:22am UTC](https://discuss.emberjs.com/t/help-me-to-see-whether-it-is-a-bug-in-rc-6/1628/2 "2013-06-26T07:22:31Z")

</div>

It seems that as of RC.6 a view’s **`controller`** property _will_ change after instantiation. Anything that observes `'controller'` or `'controller.property'` will be triggered immediately (and somewhat unexpectedly for those of us that were used to the previous behaviour). Best guess&nbsp;—&nbsp;this is something to do with the new view re-use strategy, but don’t hold me to that.

Reading through the docs for views, I gather that because **`controller`** is the default context of the view, you shouldn’t ever need to use `'controller.property'` explicitly&nbsp;— just `'property'` will do the trick. Taking this approach should protect you from observers firing at unexpected times.

[http://embersandbox.com/#/jgwhite/5865403](http://embersandbox.com/#/jgwhite/5865403)

---

<div class="post-metadata">

### Author: ![jgwhite](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jgwhite/32/3678_2.png) [@jgwhite](https://discuss.emberjs.com/u/jgwhite)
#### Post date: [June 26, 2013, 7:37am UTC](https://discuss.emberjs.com/t/help-me-to-see-whether-it-is-a-bug-in-rc-6/1628/3 "2013-06-26T07:37:54Z")

</div>

Just double-checked, and I was wrong in my assumption that you can observe just `'property'` from within the view —&nbsp;that doesn’t work. You _have_ to observe `'controller.someProperty'` and so it’s definitely a problem that the observer fires immediately.

---

<div class="post-metadata">

### Author: ![nightire](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/nightire/32/14788_2.png) [@nightire](https://discuss.emberjs.com/u/nightire)
#### Post date: [June 26, 2013, 8:02am UTC](https://discuss.emberjs.com/t/help-me-to-see-whether-it-is-a-bug-in-rc-6/1628/4 "2013-06-26T08:02:13Z")

</div>

@jgwhite If it is indeed a new change while not a bug in RC.6, well I think it’s not good enough because of the incautious side-effect, it forces me to write anti-logic codes which makes me feel very unnatural.

So, you’re right, it is definitely a problem. How should we help to fix it?

---

<div class="post-metadata">

### Author: ![jgwhite](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jgwhite/32/3678_2.png) [@jgwhite](https://discuss.emberjs.com/u/jgwhite)
#### Post date: [June 26, 2013, 10:11am UTC](https://discuss.emberjs.com/t/help-me-to-see-whether-it-is-a-bug-in-rc-6/1628/5 "2013-06-26T10:11:51Z")

</div>

I guess by writing a failing test that demonstrates the expected behaviour.

---

<div class="post-metadata">

### Author: ![jgwhite](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jgwhite/32/3678_2.png) [@jgwhite](https://discuss.emberjs.com/u/jgwhite)
#### Post date: [June 27, 2013, 6:46am UTC](https://discuss.emberjs.com/t/help-me-to-see-whether-it-is-a-bug-in-rc-6/1628/6 "2013-06-27T06:46:47Z")

</div>

I just checked this against RC.4 and RC.5 and the behaviour is the same —&nbsp;observers of `'controller'` defined on views fire by the time they’re inserted into the DOM. I’m not sure Ember has ever made any guarantees about a view’s `'controller'` property not changing post-instantiation.

---

<div class="post-metadata">

### Author: ![nightire](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/nightire/32/14788_2.png) [@nightire](https://discuss.emberjs.com/u/nightire)
#### Post date: [June 27, 2013, 7:08am UTC](https://discuss.emberjs.com/t/help-me-to-see-whether-it-is-a-bug-in-rc-6/1628/7 "2013-06-27T07:08:12Z")

</div>

But the same code works totally different in RC.5… how to explain that? No matter Ember guaranty this behavior or not, at least it should be stay the same in every version. If it has to be changed, developers should also be noticed about it, am I right?

Anyway, thanks for your patience. I’m not complaining, I just don’t feel comfortable about this.

---

<div class="post-metadata">

### Author: ![sly7\_7](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/sly7_7/32/3567_2.png) [@sly7\_7](https://discuss.emberjs.com/u/sly7_7)
#### Post date: [June 27, 2013, 7:12am UTC](https://discuss.emberjs.com/t/help-me-to-see-whether-it-is-a-bug-in-rc-6/1628/8 "2013-06-27T07:12:55Z")

</div>

@nightire Since it seems like a bug, could you please close this discussion topic and file an issue in GH ? If you could provide a jsbin/jsfiddle reproducing the two different behaviors, it would be great 😃

That beeing said, perhaps something has changed during the view/controller wiring, so that instead of the view is instantiated with the controller, perhaps now the controller is beeing set later, so the observer fire… just a guess though, not sure at all…

---

<div class="post-metadata">

### Author: ![jgwhite](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jgwhite/32/3678_2.png) [@jgwhite](https://discuss.emberjs.com/u/jgwhite)
#### Post date: [June 27, 2013, 7:18am UTC](https://discuss.emberjs.com/t/help-me-to-see-whether-it-is-a-bug-in-rc-6/1628/9 "2013-06-27T07:18:56Z")

</div>

Yeah, a JSFiddle would be awesome. There are a few `toggleProperty` calls in your example above which make it a little difficult to isolate the issue.

I’m less convinced this is strictly a bug though, more a gotcha that could be documented, i.e.:

> The `controller` property will change during a view’s lifecycle, so be careful when defining observers within views to `'controller.someProperty'` as the may fire earlier than you expect.

---

<div class="post-metadata">

### Author: ![nightire](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/nightire/32/14788_2.png) [@nightire](https://discuss.emberjs.com/u/nightire)
#### Post date: [June 27, 2013, 7:27am UTC](https://discuss.emberjs.com/t/help-me-to-see-whether-it-is-a-bug-in-rc-6/1628/10 "2013-06-27T07:27:42Z")

</div>

I’m a newbie and never file an issue in GH, so I’m just hesitates…but yes, I’ll try to reproduce this issue, thanks.
