From 8ee5ff21bd407f26c5de3079520a134fb22df25d Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Thu, 24 Mar 2016 10:50:35 -0400 Subject: [PATCH 1/2] Remove Ember.ContainerView. --- .../ember-htmlbars/tests/helpers/view_test.js | 27 - .../integration/binding_integration_test.js | 54 -- packages/ember-views/lib/index.js | 2 - .../lib/mixins/view_context_support.js | 2 +- .../ember-views/lib/mixins/view_support.js | 11 +- .../ember-views/lib/views/container_view.js | 337 ------- packages/ember-views/lib/views/view.js | 1 - .../tests/system/event_dispatcher_test.js | 85 +- .../tests/views/container_view_test.js | 880 ------------------ .../tests/views/view/append_to_test.js | 125 +-- .../tests/views/view/context_test.js | 54 -- .../tests/views/view/controller_test.js | 92 -- .../tests/views/view/create_element_test.js | 70 -- .../tests/views/view/destroy_element_test.js | 33 - .../tests/views/view/element_test.js | 14 - .../tests/views/view/is_visible_test.js | 168 ---- .../tests/views/view/remove_test.js | 37 - 17 files changed, 75 insertions(+), 1917 deletions(-) delete mode 100644 packages/ember-views/lib/views/container_view.js delete mode 100644 packages/ember-views/tests/views/container_view_test.js delete mode 100644 packages/ember-views/tests/views/view/context_test.js delete mode 100644 packages/ember-views/tests/views/view/controller_test.js diff --git a/packages/ember-htmlbars/tests/helpers/view_test.js b/packages/ember-htmlbars/tests/helpers/view_test.js index 72410682123..b3b2741dc38 100644 --- a/packages/ember-htmlbars/tests/helpers/view_test.js +++ b/packages/ember-htmlbars/tests/helpers/view_test.js @@ -8,7 +8,6 @@ import run from 'ember-metal/run_loop'; import jQuery from 'ember-views/system/jquery'; import TextField from 'ember-views/views/text_field'; import EmberObject from 'ember-runtime/system/object'; -import ContainerView from 'ember-views/views/container_view'; import SafeString from 'htmlbars-util/safe-string'; import precompile from 'ember-template-compiler/compat/precompile'; import compile from 'ember-template-compiler/system/compile'; @@ -1021,32 +1020,6 @@ QUnit.test('should expose a controller that can be used in the view instance', f equal(controller, childThingController, 'childThing should get the same controller as the outer scope'); }); -QUnit.test('should expose a controller keyword that persists through Ember.ContainerView', function() { - var templateString = '{{view view.containerView}}'; - view = EmberView.create({ - [OWNER]: owner, - containerView: ContainerView, - controller: EmberObject.create({ - foo: 'bar' - }), - - template: compile(templateString) - }); - - runAppend(view); - - var containerView = get(view, 'childViews.firstObject'); - var viewInstanceToBeInserted = EmberView.create({ - template: compile('{{controller.foo}}') - }); - - run(function() { - containerView.pushObject(viewInstanceToBeInserted); - }); - - equal(trim(viewInstanceToBeInserted.$().text()), 'bar', 'renders value from parent\'s controller'); -}); - QUnit.test('should work with precompiled templates', function() { var templateString = precompile('{{view.value}}'); var compiledTemplate = template(eval(templateString)); diff --git a/packages/ember-htmlbars/tests/integration/binding_integration_test.js b/packages/ember-htmlbars/tests/integration/binding_integration_test.js index a332e5d51b0..e843893954e 100644 --- a/packages/ember-htmlbars/tests/integration/binding_integration_test.js +++ b/packages/ember-htmlbars/tests/integration/binding_integration_test.js @@ -5,13 +5,10 @@ import EmberView from 'ember-views/views/view'; import { Binding } from 'ember-metal/binding'; import EmberObject from 'ember-runtime/system/object'; import { computed } from 'ember-metal/computed'; -import ContainerView from 'ember-views/views/container_view'; import compile from 'ember-template-compiler/system/compile'; import { runAppend, runDestroy } from 'ember-runtime/tests/utils'; import { registerHelper } from 'ember-htmlbars/helpers'; -import { set } from 'ember-metal/property_set'; - import { registerKeyword, resetKeyword } from 'ember-htmlbars/tests/utils'; import viewKeyword from 'ember-htmlbars/keywords/view'; @@ -123,57 +120,6 @@ QUnit.test('should cleanup bound properties on rerender', function() { equal(view.$().text(), 'wycats', 'rendered binding'); }); -QUnit.test('should update bound values after view\'s parent is removed and then re-appended', function() { - expectDeprecation('Setting `childViews` on a Container is deprecated.'); - - var controller = EmberObject.create(); - - var parentView = ContainerView.create({ - childViews: ['testView'], - - controller: controller, - - testView: EmberView.create({ - template: compile('{{#if showStuff}}{{boundValue}}{{else}}Not true.{{/if}}') - }) - }); - - controller.setProperties({ - showStuff: true, - boundValue: 'foo' - }); - - runAppend(parentView); - view = parentView.get('testView'); - - equal(trim(view.$().text()), 'foo'); - run(function() { - set(controller, 'showStuff', false); - }); - equal(trim(view.$().text()), 'Not true.'); - - run(function() { - set(controller, 'showStuff', true); - }); - equal(trim(view.$().text()), 'foo'); - - run(function() { - parentView.remove(); - set(controller, 'showStuff', false); - }); - run(function() { - set(controller, 'showStuff', true); - }); - runAppend(parentView); - - run(function() { - set(controller, 'boundValue', 'bar'); - }); - equal(trim(view.$().text()), 'bar'); - - runDestroy(parentView); -}); - QUnit.test('should accept bindings as a string or an Ember.Binding', function() { var ViewWithBindings = EmberView.extend({ twoWayBindingTestBinding: Binding.from('context.direction'), diff --git a/packages/ember-views/lib/index.js b/packages/ember-views/lib/index.js index 693e857b236..adac1826a13 100644 --- a/packages/ember-views/lib/index.js +++ b/packages/ember-views/lib/index.js @@ -20,7 +20,6 @@ import { import { Renderer } from 'ember-metal-views'; import { DeprecatedCoreView } from 'ember-views/views/core_view'; import { DeprecatedView } from 'ember-views/views/view'; -import { DeprecatedContainerView } from 'ember-views/views/container_view'; import Component from 'ember-views/components/component'; import EventDispatcher from 'ember-views/system/event_dispatcher'; @@ -59,7 +58,6 @@ if (Ember.ENV._ENABLE_LEGACY_VIEW_SUPPORT) { Ember.View.states = states; Ember.View.cloneStates = cloneStates; Ember.View._Renderer = Renderer; - Ember.ContainerView = DeprecatedContainerView; } Ember._Renderer = Renderer; diff --git a/packages/ember-views/lib/mixins/view_context_support.js b/packages/ember-views/lib/mixins/view_context_support.js index 925068bd732..2ef8e939ba0 100644 --- a/packages/ember-views/lib/mixins/view_context_support.js +++ b/packages/ember-views/lib/mixins/view_context_support.js @@ -43,7 +43,7 @@ var ViewContextSupport = Mixin.create(LegacyViewSupport, { 1. Supplied context (usually by Handlebars) 2. Specified controller - 3. `parentView`'s context (for a child of a ContainerView) + 3. `parentView`'s context The code in Handlebars that overrides the `_context` property first checks to see whether the view has a specified controller. This is diff --git a/packages/ember-views/lib/mixins/view_support.js b/packages/ember-views/lib/mixins/view_support.js index fe1538787e2..412dcf6be03 100644 --- a/packages/ember-views/lib/mixins/view_support.js +++ b/packages/ember-views/lib/mixins/view_support.js @@ -246,10 +246,9 @@ export default Mixin.create({ finished synchronizing. This is not typically a function that you will need to call directly when - building your application. You might consider using `Ember.ContainerView` - instead. If you do need to use `appendTo`, be sure that the target element - you are providing is associated with an `Ember.Application` and does not - have an ancestor element that is associated with an Ember view. + building your application. If you do need to use `appendTo`, be sure that + the target element you are providing is associated with an `Ember.Application` + and does not have an ancestor element that is associated with an Ember view. @method appendTo @param {String|DOMElement|jQuery} A selector, element, HTML string, or jQuery object @@ -263,7 +262,7 @@ export default Mixin.create({ let target = $(selector); assert('You tried to append to (' + selector + ') but that isn\'t in the DOM', target.length > 0); - assert('You cannot append to an existing Ember.View. Consider using Ember.ContainerView instead.', !target.is('.ember-view') && !target.parents().is('.ember-view')); + assert('You cannot append to an existing Ember.View.', !target.is('.ember-view') && !target.parents().is('.ember-view')); this.renderer.appendTo(this, target[0]); } else { @@ -349,7 +348,7 @@ export default Mixin.create({ var target = jQuery(selector); assert('You tried to replace in (' + selector + ') but that isn\'t in the DOM', target.length > 0); - assert('You cannot replace an existing Ember.View. Consider using Ember.ContainerView instead.', !target.is('.ember-view') && !target.parents().is('.ember-view')); + assert('You cannot replace an existing Ember.View.', !target.is('.ember-view') && !target.parents().is('.ember-view')); this.renderer.replaceIn(this, target[0]); diff --git a/packages/ember-views/lib/views/container_view.js b/packages/ember-views/lib/views/container_view.js deleted file mode 100644 index d796e0d3813..00000000000 --- a/packages/ember-views/lib/views/container_view.js +++ /dev/null @@ -1,337 +0,0 @@ -import isEnabled from 'ember-metal/features'; -import Ember from 'ember-metal/core'; -import { assert, deprecate } from 'ember-metal/debug'; -import MutableArray from 'ember-runtime/mixins/mutable_array'; -import { A as emberA } from 'ember-runtime/system/native_array'; -import View from 'ember-views/views/view'; - -import { get } from 'ember-metal/property_get'; -import { set } from 'ember-metal/property_set'; -import { observer } from 'ember-metal/mixin'; -import { on } from 'ember-metal/events'; - -import containerViewTemplate from 'ember-htmlbars/templates/container-view'; - -if (!isEnabled('ember-glimmer')) { - containerViewTemplate.meta.revision = 'Ember@VERSION_STRING_PLACEHOLDER'; -} - -/** -@module ember -@submodule ember-views -*/ - -/** - A `ContainerView` is an `Ember.View` subclass that implements `Ember.MutableArray` - allowing programmatic management of its child views. - - ## Setting Initial Child Views - - The initial array of child views can be set in one of two ways. You can - provide a `childViews` property at creation time that contains instance of - `Ember.View`: - - ```javascript - aContainer = Ember.ContainerView.create({ - childViews: [Ember.View.create(), Ember.View.create()] - }); - ``` - - You can also provide a list of property names whose values are instances of - `Ember.View`: - - ```javascript - aContainer = Ember.ContainerView.create({ - childViews: ['aView', 'bView', 'cView'], - aView: Ember.View.create(), - bView: Ember.View.create(), - cView: Ember.View.create() - }); - ``` - - The two strategies can be combined: - - ```javascript - aContainer = Ember.ContainerView.create({ - childViews: ['aView', Ember.View.create()], - aView: Ember.View.create() - }); - ``` - - Each child view's rendering will be inserted into the container's rendered - HTML in the same order as its position in the `childViews` property. - - ## Adding and Removing Child Views - - The container view implements `Ember.MutableArray` allowing programmatic management of its child views. - - To remove a view, pass that view into a `removeObject` call on the container view. - - Given an empty `` the following code - - ```javascript - aContainer = Ember.ContainerView.create({ - classNames: ['the-container'], - childViews: ['aView', 'bView'], - aView: Ember.View.create({ - template: Ember.HTMLBars.compile("A") - }), - bView: Ember.View.create({ - template: Ember.HTMLBars.compile("B") - }) - }); - - aContainer.appendTo('body'); - ``` - - Results in the HTML - - ```html -
-
A
-
B
-
- ``` - - Removing a view - - ```javascript - aContainer.toArray(); // [aContainer.aView, aContainer.bView] - aContainer.removeObject(aContainer.get('bView')); - aContainer.toArray(); // [aContainer.aView] - ``` - - Will result in the following HTML - - ```html -
-
A
-
- ``` - - Similarly, adding a child view is accomplished by adding `Ember.View` instances to the - container view. - - Given an empty `` the following code - - ```javascript - aContainer = Ember.ContainerView.create({ - classNames: ['the-container'], - childViews: ['aView', 'bView'], - aView: Ember.View.create({ - template: Ember.HTMLBars.compile("A") - }), - bView: Ember.View.create({ - template: Ember.HTMLBars.compile("B") - }) - }); - - aContainer.appendTo('body'); - ``` - - Results in the HTML - - ```html -
-
A
-
B
-
- ``` - - Adding a view - - ```javascript - AnotherViewClass = Ember.View.extend({ - template: Ember.HTMLBars.compile("Another view") - }); - - aContainer.toArray(); // [aContainer.aView, aContainer.bView] - aContainer.pushObject(AnotherViewClass.create()); - aContainer.toArray(); // [aContainer.aView, aContainer.bView, ] - ``` - - Will result in the following HTML - - ```html -
-
A
-
B
-
Another view
-
- ``` - - ## Templates and Layout - - A `template`, `templateName`, `defaultTemplate`, `layout`, `layoutName` or - `defaultLayout` property on a container view will not result in the template - or layout being rendered. The HTML contents of a `Ember.ContainerView`'s DOM - representation will only be the rendered HTML of its child views. - - @class ContainerView - @namespace Ember - @extends Ember.View - @deprecated See http://emberjs.com/deprecations/v1.x/#toc_ember-containerview - @private -*/ -var ContainerView = View.extend(MutableArray, { - willWatchProperty(prop) { - deprecate( - 'ContainerViews should not be observed as arrays. This behavior will change in future implementations of ContainerView.', - !prop.match(/\[]/) && prop.indexOf('@') !== 0, - { id: 'ember-views.container-views-array-observed', until: '2.4.0' } - ); - }, - - init() { - this._super(...arguments); - this._prevCurrentView = undefined; - var userChildViews = get(this, 'childViews'); - deprecate( - 'Setting `childViews` on a Container is deprecated.', - Ember.isEmpty(userChildViews), - { id: 'ember-views.container-child-views', until: '2.4.0' } - ); - - // redefine view's childViews property that was obliterated - // 2.0TODO: Don't Ember.A() this so users disabling prototype extensions - // don't pay a penalty. - var childViews = this.childViews = emberA(); - - userChildViews.forEach((viewName, idx) => { - var view; - - if ('string' === typeof viewName) { - view = get(this, viewName); - view = this.createChildView(view); - set(this, viewName, view); - } else { - view = this.createChildView(viewName); - } - - childViews[idx] = view; - }); - - var currentView = get(this, 'currentView'); - if (currentView) { - if (!childViews.length) { childViews = this.childViews = emberA(this.childViews.slice()); } - childViews.push(this.createChildView(currentView)); - } - - set(this, 'length', childViews.length); - }, - - // Normally parentView and childViews are managed at render time. However, - // the ContainerView is an unusual legacy case. People expect to be able to - // push a child view into the ContainerView and have its parentView set - // appropriately. As a result, we link the child nodes ahead of time and - // ignore render-time linking. - appendChild(view) { - // This occurs if the view being appended is the empty view, rather than - // a view eagerly inserted into the childViews array. - if (view.parentView !== this) { - this.linkChild(view); - } - }, - - _currentViewDidChange: observer('currentView', function() { - var prevView = this._prevCurrentView; - if (prevView) { - prevView.destroy(); - } - var currentView = get(this, 'currentView'); - this._prevCurrentView = currentView; - if (currentView) { - assert('You tried to set a current view that already has a parent. Make sure you don\'t have multiple outlets in the same view.', !currentView.parentView); - this.pushObject(currentView); - } - }), - - layout: containerViewTemplate, - - replace(idx, removedCount, addedViews=[]) { - let addedCount = get(addedViews, 'length'); - let childViews = get(this, 'childViews'); - - assert('You can\'t add a child to a container - the child is already a child of another view', () => { - for (let i = 0, l = addedViews.length; i < l; i++) { - let item = addedViews[i]; - if (item.parentView && item.parentView !== this) { return false; } - } - return true; - }()); - - this.arrayContentWillChange(idx, removedCount, addedCount); - - // Normally parentView and childViews are managed at render time. However, - // the ContainerView is an unusual legacy case. People expect to be able to - // push a child view into the ContainerView and have its parentView set - // appropriately. - // - // Because of this, we synchronously fix up the parentView/childViews tree - // as soon as views are added or removed, despite the fact that this will - // happen automatically when we render. - let removedViews = childViews.slice(idx, idx + removedCount); - removedViews.forEach(view => this.unlinkChild(view)); - addedViews.forEach(view => this.linkChild(view)); - - childViews.splice(idx, removedCount, ...addedViews); - - this.notifyPropertyChange('childViews'); - this.arrayContentDidChange(idx, removedCount, addedCount); - - // assert("You can't add a child to a container - the child is already a child of another view", emberA(addedViews).every(function(item) { return !item.parentView || item.parentView === self; })); - - set(this, 'length', childViews.length); - - return this; - }, - - objectAt(idx) { - return this.childViews[idx]; - }, - - _triggerChildWillDestroyElement: on('willDestroyElement', function () { - var childViews = this.childViews; - if (childViews) { - for (var i = 0; i < childViews.length; i++) { - this.renderer.willDestroyElement(childViews[i]); - } - } - }), - - _triggerChildDidDestroyElement: on('didDestroyElement', function () { - var childViews = this.childViews; - if (childViews) { - for (var i = 0; i < childViews.length; i++) { - this.renderer.didDestroyElement(childViews[i]); - } - } - }) -}); - -function containerViewDeprecationMessage() { - deprecate( - 'Ember.ContainerView is deprecated.', - !!Ember.ENV._ENABLE_LEGACY_VIEW_SUPPORT, - { - url: 'http://emberjs.com/deprecations/v1.x/#toc_ember-containerview', - id: 'ember-views.container-view', - until: '2.4.0' - } - ); -} - -export var DeprecatedContainerView = ContainerView.extend({ - init() { - containerViewDeprecationMessage(); - this._super(...arguments); - } -}); - -DeprecatedContainerView.reopen = function() { - containerViewDeprecationMessage(); - ContainerView.reopen(...arguments); - return this; -}; - -export default ContainerView; diff --git a/packages/ember-views/lib/views/view.js b/packages/ember-views/lib/views/view.js index eb4158b802a..5b5e52eb502 100644 --- a/packages/ember-views/lib/views/view.js +++ b/packages/ember-views/lib/views/view.js @@ -1,5 +1,4 @@ // jQuery, Ember.lookup, -// Ember.ContainerView circular dependency // Ember.ENV import Ember from 'ember-metal/core'; import { deprecate } from 'ember-metal/debug'; diff --git a/packages/ember-views/tests/system/event_dispatcher_test.js b/packages/ember-views/tests/system/event_dispatcher_test.js index 2d7d573c884..1ead71336b1 100644 --- a/packages/ember-views/tests/system/event_dispatcher_test.js +++ b/packages/ember-views/tests/system/event_dispatcher_test.js @@ -6,13 +6,17 @@ import EmberObject from 'ember-runtime/system/object'; import jQuery from 'ember-views/system/jquery'; import View from 'ember-views/views/view'; import EventDispatcher from 'ember-views/system/event_dispatcher'; -import ContainerView from 'ember-views/views/container_view'; import compile from 'ember-template-compiler/system/compile'; +import ComponentLookup from 'ember-views/component_lookup'; +import Component from 'ember-views/components/component'; +import buildOwner from 'container/tests/test-helpers/build-owner'; +import { OWNER } from 'container/owner'; +import { runAppend, runDestroy } from 'ember-runtime/tests/utils'; import { registerKeyword, resetKeyword } from 'ember-htmlbars/tests/utils'; import viewKeyword from 'ember-htmlbars/keywords/view'; -var view, originalViewKeyword; +var owner, view, originalViewKeyword; var dispatcher; import isEnabled from 'ember-metal/features'; @@ -22,17 +26,23 @@ if (!isEnabled('ember-glimmer')) { QUnit.module('EventDispatcher', { setup() { originalViewKeyword = registerKeyword('view', viewKeyword); - run(function() { - dispatcher = EventDispatcher.create(); - dispatcher.setup(); - }); + + owner = buildOwner(); + owner.registerOptionsForType('component', { singleton: false }); + owner.registerOptionsForType('view', { singleton: false }); + owner.registerOptionsForType('template', { instantiate: false }); + owner.register('component-lookup:main', ComponentLookup); + owner.register('event_dispatcher:main', EventDispatcher); + + dispatcher = owner.lookup('event_dispatcher:main'); + + run(dispatcher, 'setup'); }, teardown() { - run(function() { - if (view) { view.destroy(); } - dispatcher.destroy(); - }); + runDestroy(view); + runDestroy(owner); + resetKeyword('view', originalViewKeyword); } }); @@ -148,29 +158,28 @@ QUnit.test('should send change events up view hierarchy if view contains form el QUnit.test('events should stop propagating if the view is destroyed', function() { var parentViewReceived, receivedEvent; - var parentView = ContainerView.create({ + owner.register('component:x-foo', Component.extend({ change(evt) { - parentViewReceived = true; + receivedEvent = true; + run(() => { + get(this, 'parentView').destroy(); + }); } - }); + })); - view = parentView.createChildView(View, { - template: compile(''), + owner.register('template:components/x-foo', compile(' 0, 'creates and appends the view\'s element'); }); -QUnit.module('EmberView - removing views in a view hierarchy', { - setup() { - originalViewKeyword = registerKeyword('view', viewKeyword); - expectDeprecation('Setting `childViews` on a Container is deprecated.'); - - willDestroyCalled = 0; - - view = ContainerView.create({ - childViews: ['child'], - child: EmberView.create({ - willDestroyElement() { - willDestroyCalled++; - } - }) - }); - - childView = get(view, 'child'); - }, - - teardown() { - run(function() { - if (!view.isDestroyed) { view.destroy(); } - }); - resetKeyword('view', originalViewKeyword); - } -}); - -QUnit.test('remove removes child elements from the DOM', function() { - ok(!get(childView, 'element'), 'precond - should not have an element'); - - run(function() { - view.append(); - }); - - ok(jQuery('#' + get(childView, 'elementId')).length === 1, 'precond - element was inserted'); - - // remove parent view - run(function() { - view.remove(); - }); - - ok(jQuery('#' + get(childView, 'elementId')).length === 0, 'remove removes child elements the DOM'); - ok(EmberView.views[get(childView, 'elementId')] === undefined, 'remove does not remove child views from the view hash'); - ok(!get(childView, 'element'), 'remove nulls out child elements'); - equal(willDestroyCalled, 1, 'the willDestroyElement hook was called once'); -}); - -QUnit.test('destroy more forcibly removes child views', function() { - ok(!get(childView, 'element'), 'precond - should not have an element'); - - run(function() { - view.append(); - }); - - ok(jQuery('#' + get(childView, 'elementId')).length === 1, 'precond - child element was inserted'); - - willDestroyCalled = 0; - - run(function() { - view.destroy(); - }); - - ok(jQuery('#' + get(childView, 'elementId')).length === 0, 'destroy removes child elements from the DOM'); - ok(EmberView.views[get(childView, 'elementId')] === undefined, 'destroy removes a child views from the global views hash'); - equal(get(childView, 'isDestroyed'), true, 'child views are marked as destroyed'); - ok(!get(childView, 'element'), 'child views no longer have an element'); - equal(willDestroyCalled, 1, 'the willDestroyElement hook was called once on children'); -}); - -QUnit.test('destroy removes a child view from its parent', function() { - ok(!get(childView, 'element'), 'precond - should not have an element'); - - run(function() { - view.append(); - }); - - ok(jQuery('#' + get(childView, 'elementId')).length === 1, 'precond - child element was inserted'); - - run(function() { - childView.destroy(); - }); - - ok(get(view, 'childViews.length') === 0, 'Destroyed child views should be removed from their parent'); -}); - } diff --git a/packages/ember-views/tests/views/view/context_test.js b/packages/ember-views/tests/views/view/context_test.js deleted file mode 100644 index 192bdcbae0b..00000000000 --- a/packages/ember-views/tests/views/view/context_test.js +++ /dev/null @@ -1,54 +0,0 @@ -import run from 'ember-metal/run_loop'; - -import EmberView from 'ember-views/views/view'; -import ContainerView from 'ember-views/views/container_view'; - -import { registerKeyword, resetKeyword } from 'ember-htmlbars/tests/utils'; -import viewKeyword from 'ember-htmlbars/keywords/view'; - -var originalViewKeyword; - -QUnit.module('EmberView - context property', { - setup() { - originalViewKeyword = registerKeyword('view', viewKeyword); - }, - teardown() { - resetKeyword('view', originalViewKeyword); - } -}); - -QUnit.test('setting a controller on an inner view should change it context', function() { - var App = {}; - var a = { name: 'a' }; - var b = { name: 'b' }; - - var innerView = EmberView.create(); - var middleView = ContainerView.create(); - var outerView = App.outerView = ContainerView.create({ - controller: a - }); - - run(function() { - outerView.appendTo('#qunit-fixture'); - }); - - run(function () { - outerView.set('currentView', middleView); - }); - - run(function () { - innerView.set('controller', b); - middleView.set('currentView', innerView); - }); - - // assert - equal(outerView.get('context'), a, 'outer context correct'); - equal(middleView.get('context'), a, 'middle context correct'); - equal(innerView.get('context'), b, 'inner context correct'); - - run(function() { - innerView.destroy(); - middleView.destroy(); - outerView.destroy(); - }); -}); diff --git a/packages/ember-views/tests/views/view/controller_test.js b/packages/ember-views/tests/views/view/controller_test.js deleted file mode 100644 index 6b381b398cc..00000000000 --- a/packages/ember-views/tests/views/view/controller_test.js +++ /dev/null @@ -1,92 +0,0 @@ -import run from 'ember-metal/run_loop'; - -import ContainerView from 'ember-views/views/container_view'; - -QUnit.module('Ember.View - controller property'); - -QUnit.test('controller property should be inherited from nearest ancestor with controller', function() { - var grandparent = ContainerView.create(); - var parent = ContainerView.create(); - var child = ContainerView.create(); - var grandchild = ContainerView.create(); - - var grandparentController = {}; - var parentController = {}; - - run(function() { - grandparent.set('controller', grandparentController); - parent.set('controller', parentController); - - grandparent.pushObject(parent); - parent.pushObject(child); - }); - - strictEqual(grandparent.get('controller'), grandparentController); - strictEqual(parent.get('controller'), parentController); - strictEqual(child.get('controller'), parentController); - strictEqual(grandchild.get('controller'), null); - - run(function() { - child.pushObject(grandchild); - }); - - strictEqual(grandchild.get('controller'), parentController); - - var newController = {}; - run(function() { - parent.set('controller', newController); - }); - - strictEqual(parent.get('controller'), newController); - strictEqual(child.get('controller'), newController); - strictEqual(grandchild.get('controller'), newController); - - run(function() { - grandparent.destroy(); - parent.destroy(); - child.destroy(); - grandchild.destroy(); - }); -}); - -QUnit.test('controller changes are passed to descendants', function() { - var grandparent = ContainerView.create(); - var parent = ContainerView.create(); - var child = ContainerView.create(); - var grandchild = ContainerView.create(); - - run(function() { - grandparent.set('controller', {}); - - grandparent.pushObject(parent); - parent.pushObject(child); - child.pushObject(grandchild); - }); - - var parentCount = 0; - var childCount = 0; - var grandchildCount = 0; - - parent.addObserver('controller', parent, function() { parentCount++; }); - child.addObserver('controller', child, function() { childCount++; }); - grandchild.addObserver('controller', grandchild, function() { grandchildCount++; }); - - run(function() { grandparent.set('controller', {}); }); - - equal(parentCount, 1); - equal(childCount, 1); - equal(grandchildCount, 1); - - run(function() { grandparent.set('controller', {}); }); - - equal(parentCount, 2); - equal(childCount, 2); - equal(grandchildCount, 2); - - run(function() { - grandparent.destroy(); - parent.destroy(); - child.destroy(); - grandchild.destroy(); - }); -}); diff --git a/packages/ember-views/tests/views/view/create_element_test.js b/packages/ember-views/tests/views/view/create_element_test.js index 24e35f65af4..0d9e9c1aa4d 100644 --- a/packages/ember-views/tests/views/view/create_element_test.js +++ b/packages/ember-views/tests/views/view/create_element_test.js @@ -1,7 +1,6 @@ import { get } from 'ember-metal/property_get'; import run from 'ember-metal/run_loop'; import EmberView from 'ember-views/views/view'; -import ContainerView from 'ember-views/views/container_view'; import { equalHTML } from 'ember-views/tests/test-helpers/equal-html'; import compile from 'ember-template-compiler/system/compile'; @@ -68,79 +67,10 @@ QUnit.test('calls render and turns resultant string into element', function() { view.createElement(); }); - var elem = get(view, 'element'); ok(elem, 'has element now'); equal(elem.innerHTML, 'foo', 'has innerHTML from context'); equal(elem.tagName.toString().toLowerCase(), 'span', 'has tagName from view'); }); -QUnit.test('renders the child view templates in the right context', function() { - expectDeprecation('Setting `childViews` on a Container is deprecated.'); - - view = ContainerView.create({ - tagName: 'table', - childViews: [ - EmberView.create({ - tagName: '', - template: compile('snorfblax') - }) - ] - }); - - equal(get(view, 'element'), null, 'precondition - has no element'); - run(function() { - view.createElement(); - }); - - - var elem = get(view, 'element'); - ok(elem, 'has element now'); - equal(elem.tagName.toString().toLowerCase(), 'table', 'has tagName from view'); - equalHTML(elem.childNodes, 'snorfblax', 'has innerHTML from context'); -}); - -QUnit.test('does not wrap many tr children in tbody elements', function() { - expectDeprecation('Setting `childViews` on a Container is deprecated.'); - - view = ContainerView.create({ - tagName: 'table', - childViews: [ - EmberView.create({ - tagName: '', - template: compile('snorfblax') - }), - EmberView.create({ - tagName: '', - template: compile('snorfblax') - }) - ] - }); - - equal(get(view, 'element'), null, 'precondition - has no element'); - run(function() { - view.createElement(); - }); - - - var elem = get(view, 'element'); - ok(elem, 'has element now'); - equalHTML(elem.childNodes, 'snorfblaxsnorfblax', 'has innerHTML from context'); - equal(elem.tagName.toString().toLowerCase(), 'table', 'has tagName from view'); -}); - -QUnit.test('generated element include HTML from child views as well', function() { - expectDeprecation('Setting `childViews` on a Container is deprecated.'); - - view = ContainerView.create({ - childViews: [EmberView.create({ elementId: 'foo' })] - }); - - run(function() { - view.createElement(); - }); - - ok(view.$('#foo').length, 'has element with child elementId'); -}); - } diff --git a/packages/ember-views/tests/views/view/destroy_element_test.js b/packages/ember-views/tests/views/view/destroy_element_test.js index cb7d1bcfcc6..19ce1bc66ac 100644 --- a/packages/ember-views/tests/views/view/destroy_element_test.js +++ b/packages/ember-views/tests/views/view/destroy_element_test.js @@ -1,7 +1,6 @@ import { get } from 'ember-metal/property_get'; import run from 'ember-metal/run_loop'; import EmberView from 'ember-views/views/view'; -import ContainerView from 'ember-views/views/container_view'; import { registerKeyword, resetKeyword } from 'ember-htmlbars/tests/utils'; import viewKeyword from 'ember-htmlbars/keywords/view'; @@ -38,38 +37,6 @@ QUnit.test('if it has no element, does nothing', function() { equal(callCount, 0, 'did not invoke callback'); }); -QUnit.test('if it has a element, calls willDestroyElement on receiver and child views then deletes the element', function() { - expectDeprecation('Setting `childViews` on a Container is deprecated.'); - - var parentCount = 0; - var childCount = 0; - - view = ContainerView.create({ - willDestroyElement() { parentCount++; }, - childViews: [ContainerView.extend({ - // no willDestroyElement here... make sure no errors are thrown - childViews: [EmberView.extend({ - willDestroyElement() { childCount++; } - })] - })] - }); - - run(function() { - view.createElement(); - }); - - ok(get(view, 'element'), 'precond - view has element'); - - run(function() { - view.destroyElement(); - }); - - equal(parentCount, 1, 'invoked destroy element on the parent'); - equal(childCount, 1, 'invoked destroy element on the child'); - ok(!get(view, 'element'), 'view no longer has element'); - ok(!get(objectAt(get(view, 'childViews'), 0), 'element'), 'child no longer has an element'); -}); - QUnit.test('returns receiver', function() { var ret; view = EmberView.create(); diff --git a/packages/ember-views/tests/views/view/element_test.js b/packages/ember-views/tests/views/view/element_test.js index 7b62f270226..310959389a0 100644 --- a/packages/ember-views/tests/views/view/element_test.js +++ b/packages/ember-views/tests/views/view/element_test.js @@ -5,7 +5,6 @@ import { set } from 'ember-metal/property_set'; import run from 'ember-metal/run_loop'; import EmberView from 'ember-views/views/view'; -import ContainerView from 'ember-views/views/container_view'; import { objectAt } from 'ember-runtime/mixins/array'; @@ -26,19 +25,6 @@ QUnit.test('returns null if the view has no element and no parent view', functio equal(get(view, 'element'), null, 'has no element'); }); -QUnit.test('returns null if the view has no element and parent view has no element', function() { - expectDeprecation('Setting `childViews` on a Container is deprecated.'); - - parentView = ContainerView.create({ - childViews: [EmberView.extend()] - }); - view = objectAt(get(parentView, 'childViews'), 0); - - equal(get(view, 'parentView'), parentView, 'precond - has parent view'); - equal(get(parentView, 'element'), null, 'parentView has no element'); - equal(get(view, 'element'), null, ' has no element'); -}); - QUnit.test('returns element if you set the value', function() { view = EmberView.create(); equal(get(view, 'element'), null, 'precond- has no element'); diff --git a/packages/ember-views/tests/views/view/is_visible_test.js b/packages/ember-views/tests/views/view/is_visible_test.js index c9b5e2ca89c..e565b8ae1eb 100644 --- a/packages/ember-views/tests/views/view/is_visible_test.js +++ b/packages/ember-views/tests/views/view/is_visible_test.js @@ -4,7 +4,6 @@ import { set } from 'ember-metal/property_set'; import run from 'ember-metal/run_loop'; import { computed } from 'ember-metal/computed'; import EmberView from 'ember-views/views/view'; -import ContainerView from 'ember-views/views/container_view'; import { registerKeyword, resetKeyword } from 'ember-htmlbars/tests/utils'; import viewKeyword from 'ember-htmlbars/keywords/view'; @@ -134,170 +133,3 @@ QUnit.test('doesn\'t overwrite existing style attribute bindings', function() { equal(view.$().attr('style'), 'color: blue; display: none;', 'has concatenated style attribute'); }); - -QUnit.module('EmberView#isVisible with Container', { - setup() { - originalViewKeyword = registerKeyword('view', viewKeyword); - expectDeprecation('Setting `childViews` on a Container is deprecated.'); - - parentBecameVisible = 0; - childBecameVisible = 0; - grandchildBecameVisible = 0; - parentBecameHidden = 0; - childBecameHidden = 0; - grandchildBecameHidden = 0; - - View = ContainerView.extend({ - childViews: ['child'], - becameVisible() { parentBecameVisible++; }, - becameHidden() { parentBecameHidden++; }, - - child: ContainerView.extend({ - childViews: ['grandchild'], - becameVisible() { childBecameVisible++; }, - becameHidden() { childBecameHidden++; }, - - grandchild: EmberView.extend({ - template() { return 'seems weird bro'; }, - becameVisible() { grandchildBecameVisible++; }, - becameHidden() { grandchildBecameHidden++; } - }) - }) - }); - }, - - teardown() { - if (view) { - run(function() { view.destroy(); }); - } - resetKeyword('view', originalViewKeyword); - } -}); - -QUnit.test('view should be notified after isVisible is set to false and the element has been hidden', function() { - run(function() { - view = View.create({ isVisible: false }); - view.append(); - }); - - ok(view.$().is(':hidden'), 'precond - view is hidden when appended'); - - run(function() { - view.set('isVisible', true); - }); - - ok(view.$().is(':visible'), 'precond - view is now visible'); - equal(parentBecameVisible, 1); - equal(childBecameVisible, 1); - equal(grandchildBecameVisible, 1); -}); - -QUnit.test('view should be notified after isVisible is set to false and the element has been hidden', function() { - run(function() { - view = View.create({ isVisible: false }); - view.append(); - }); - - ok(view.$().is(':hidden'), 'precond - view is hidden when appended'); - - run(function() { - view.set('isVisible', true); - }); - - ok(view.$().is(':visible'), 'precond - view is now visible'); - equal(parentBecameVisible, 1); - equal(childBecameVisible, 1); - equal(grandchildBecameVisible, 1); -}); - -QUnit.test('view should be notified after isVisible is set to false and the element has been hidden', function() { - view = View.create({ isVisible: true }); - //var childView = objectAt(view.get('childViews'), 0); - - run(function() { - view.append(); - }); - - ok(view.$().is(':visible'), 'precond - view is visible when appended'); - - run(function() { - view.set('isVisible', false); - }); - - ok(view.$().is(':hidden'), 'precond - view is now hidden'); -}); - -QUnit.test('view should be notified after isVisible is set to true and the element has been shown', function() { - view = View.create({ isVisible: false }); - - run(function() { - view.append(); - }); - - ok(view.$().is(':hidden'), 'precond - view is hidden when appended'); - - run(function() { - view.set('isVisible', true); - }); - - ok(view.$().is(':visible'), 'precond - view is now visible'); - - equal(parentBecameVisible, 1); - equal(childBecameVisible, 1); - equal(grandchildBecameVisible, 1); -}); - -QUnit.test('if a view descends from a hidden view, making isVisible true should not trigger becameVisible', function() { - view = View.create({ isVisible: true }); - var childView = objectAt(view.get('childViews'), 0); - - run(function() { - view.append(); - }); - - ok(view.$().is(':visible'), 'precond - view is visible when appended'); - - run(function() { - childView.set('isVisible', false); - }); - - run(function() { - view.set('isVisible', false); - }); - - childBecameVisible = 0; - grandchildBecameVisible = 0; - - run(function() { - childView.set('isVisible', true); - }); - - equal(childBecameVisible, 0, 'the child did not become visible'); - equal(grandchildBecameVisible, 0, 'the grandchild did not become visible'); -}); - -QUnit.test('if a child view becomes visible while its parent is hidden, if its parent later becomes visible, it receives a becameVisible callback', function() { - view = View.create({ isVisible: false }); - var childView = objectAt(view.get('childViews'), 0); - - run(function() { - view.append(); - }); - - ok(view.$().is(':hidden'), 'precond - view is hidden when appended'); - - run(function() { - childView.set('isVisible', true); - }); - - equal(childBecameVisible, 0, 'child did not become visible since parent is hidden'); - equal(grandchildBecameVisible, 0, 'grandchild did not become visible since parent is hidden'); - - run(function() { - view.set('isVisible', true); - }); - - equal(parentBecameVisible, 1); - equal(childBecameVisible, 1); - equal(grandchildBecameVisible, 1); -}); diff --git a/packages/ember-views/tests/views/view/remove_test.js b/packages/ember-views/tests/views/view/remove_test.js index 061760f6502..9a9ccfe357c 100644 --- a/packages/ember-views/tests/views/view/remove_test.js +++ b/packages/ember-views/tests/views/view/remove_test.js @@ -2,7 +2,6 @@ import { get } from 'ember-metal/property_get'; import run from 'ember-metal/run_loop'; import jQuery from 'ember-views/system/jquery'; import View from 'ember-views/views/view'; -import ContainerView from 'ember-views/views/container_view'; import { registerKeyword, resetKeyword } from 'ember-htmlbars/tests/utils'; import viewKeyword from 'ember-htmlbars/keywords/view'; @@ -10,44 +9,8 @@ import viewKeyword from 'ember-htmlbars/keywords/view'; import { objectAt } from 'ember-runtime/mixins/array'; -// ....................................................... -// removeChild() -// - var parentView, child; var originalViewKeyword; -QUnit.module('View#removeChild', { - setup() { - originalViewKeyword = registerKeyword('view', viewKeyword); - expectDeprecation('Setting `childViews` on a Container is deprecated.'); - - parentView = ContainerView.create({ childViews: [View] }); - child = objectAt(get(parentView, 'childViews'), 0); - }, - teardown() { - run(function() { - parentView.destroy(); - child.destroy(); - }); - resetKeyword('view', originalViewKeyword); - } -}); - -QUnit.test('returns receiver', function() { - equal(parentView.removeChild(child), parentView, 'receiver'); -}); - -QUnit.test('removes child from parent.childViews array', function() { - ok(get(parentView, 'childViews').indexOf(child)>=0, 'precond - has child in childViews array before remove'); - parentView.removeChild(child); - ok(get(parentView, 'childViews').indexOf(child) < 0, 'removed child'); -}); - -QUnit.test('sets parentView property to null', function() { - ok(get(child, 'parentView'), 'precond - has parentView'); - parentView.removeChild(child); - ok(!get(child, 'parentView'), 'parentView is now null'); -}); // ....................................................... // removeAllChildren() From 2e99a02d875ed10118d6cfabfd2c7be99e3d3418 Mon Sep 17 00:00:00 2001 From: Eric Kelly Date: Sun, 27 Mar 2016 15:41:27 -0700 Subject: [PATCH 2/2] Remove Ember.ContainerView cont. --- .../lib/templates/container-view.hbs | 1 - .../tests/system/event_dispatcher_test.js | 21 +++--- .../tests/views/view/create_element_test.js | 1 - .../tests/views/view/destroy_element_test.js | 2 - .../tests/views/view/element_test.js | 2 - .../tests/views/view/is_visible_test.js | 5 +- .../tests/views/view/remove_test.js | 69 +++++++++++-------- .../tests/views/view/replace_in_test.js | 9 ++- 8 files changed, 54 insertions(+), 56 deletions(-) delete mode 100644 packages/ember-htmlbars/lib/templates/container-view.hbs diff --git a/packages/ember-htmlbars/lib/templates/container-view.hbs b/packages/ember-htmlbars/lib/templates/container-view.hbs deleted file mode 100644 index 40419ec7485..00000000000 --- a/packages/ember-htmlbars/lib/templates/container-view.hbs +++ /dev/null @@ -1 +0,0 @@ -{{#each view.childViews key='elementId' as |childView|}}{{view childView}}{{else if view._emptyView}}{{view view._emptyView _defaultTagName=view._emptyViewTagName}}{{/each}} \ No newline at end of file diff --git a/packages/ember-views/tests/system/event_dispatcher_test.js b/packages/ember-views/tests/system/event_dispatcher_test.js index 1ead71336b1..314e5bfad68 100644 --- a/packages/ember-views/tests/system/event_dispatcher_test.js +++ b/packages/ember-views/tests/system/event_dispatcher_test.js @@ -156,9 +156,10 @@ QUnit.test('should send change events up view hierarchy if view contains form el }); QUnit.test('events should stop propagating if the view is destroyed', function() { - var parentViewReceived, receivedEvent; + var parentComponentReceived, receivedEvent; owner.register('component:x-foo', Component.extend({ + layout: compile(''), change(evt) { receivedEvent = true; run(() => { @@ -167,25 +168,21 @@ QUnit.test('events should stop propagating if the view is destroyed', function() } })); - owner.register('template:components/x-foo', compile(' runDestroy(v)); + runDestroy(view); resetKeyword('view', originalViewKeyword); } }); @@ -63,21 +74,18 @@ QUnit.module('View#removeFromParent', { } }); -import isEnabled from 'ember-metal/features'; -if (!isEnabled('ember-glimmer')) { - // jscs:disable - QUnit.test('removes view from parent view', function() { - expectDeprecation('Setting `childViews` on a Container is deprecated.'); + parentView = View.extend({ + template: compile('{{view view.childView}}'), + childView: View.extend({ + template: compile('child view template') + }) + }).create(); + run(parentView, parentView.append); - parentView = ContainerView.create({ childViews: [View] }); child = objectAt(get(parentView, 'childViews'), 0); ok(get(child, 'parentView'), 'precond - has parentView'); - run(function() { - parentView.createElement(); - }); - ok(parentView.$('div').length, 'precond - has a child DOM element'); run(function() { @@ -89,16 +97,18 @@ QUnit.test('removes view from parent view', function() { equal(parentView.$('div').length, 0, 'removes DOM element from parent'); }); -} - QUnit.test('returns receiver', function() { - expectDeprecation('Setting `childViews` on a Container is deprecated.'); - - parentView = ContainerView.create({ childViews: [View] }); + parentView = View.extend({ + template: compile('{{view view.childView}}'), + childView: View.extend({ + template: compile('child view template') + }) + }).create(); + + run(parentView, parentView.append); child = objectAt(get(parentView, 'childViews'), 0); - var removed = run(function() { - return child.removeFromParent(); - }); + + let removed = run(() => child.removeFromParent()); equal(removed, child, 'receiver'); }); @@ -116,7 +126,6 @@ QUnit.test('does nothing if not in parentView', function() { }); }); - QUnit.test('the DOM element is gone after doing append and remove in two separate runloops', function() { view = View.create(); run(function() { @@ -140,3 +149,5 @@ QUnit.test('the DOM element is gone after doing append and remove in a single ru var viewElem = jQuery('#' + get(view, 'elementId')); ok(viewElem.length === 0, 'view\'s element doesn\'t exist in DOM'); }); + +} diff --git a/packages/ember-views/tests/views/view/replace_in_test.js b/packages/ember-views/tests/views/view/replace_in_test.js index 0fef535911c..4d8764a6dbd 100644 --- a/packages/ember-views/tests/views/view/replace_in_test.js +++ b/packages/ember-views/tests/views/view/replace_in_test.js @@ -2,7 +2,7 @@ import { get } from 'ember-metal/property_get'; import run from 'ember-metal/run_loop'; import jQuery from 'ember-views/system/jquery'; import EmberView from 'ember-views/views/view'; -import ContainerView from 'ember-views/views/container_view'; +import compile from 'ember-template-compiler/system/compile'; import { registerKeyword, resetKeyword } from 'ember-htmlbars/tests/utils'; import viewKeyword from 'ember-htmlbars/keywords/view'; @@ -91,11 +91,10 @@ if (!isEnabled('ember-glimmer')) { QUnit.module('EmberView - replaceIn() in a view hierarchy', { setup() { originalViewKeyword = registerKeyword('view', viewKeyword); - expectDeprecation('Setting `childViews` on a Container is deprecated.'); - View = ContainerView.extend({ - childViews: ['child'], - child: EmberView.extend({ + View = EmberView.extend({ + template: compile('{{view view.childView}}'), + childView: EmberView.extend({ elementId: 'child' }) });