Skip to content

Commit

Permalink
Merge pull request #12163 from rwjblue/remove-currentState-reserved-word
Browse files Browse the repository at this point in the history
[BUGFIX beta] Move `View#currentState` to `View#_currentState`.
  • Loading branch information
rwjblue committed Aug 22, 2015
2 parents 1f63840 + 8195fa0 commit 12d23bc
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 15 deletions.
4 changes: 2 additions & 2 deletions packages/ember-views/lib/compat/attrs-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ AttrsProxyMixin[PROPERTY_DID_CHANGE] = function(key) {
if (this._isAngleBracket) { return; }
if (this._isDispatchingAttrs) { return; }

if (this.currentState) {
this.currentState.legacyPropertyDidChange(this, key);
if (this._currentState) {
this._currentState.legacyPropertyDidChange(this, key);
}
};

Expand Down
4 changes: 2 additions & 2 deletions packages/ember-views/lib/mixins/view_state_support.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ var ViewStateSupport = Mixin.create({
},

_transitionTo(state) {
var priorState = this.currentState;
var currentState = this.currentState = this._states[state];
var priorState = this._currentState;
var currentState = this._currentState = this._states[state];
this._state = state;

if (priorState && priorState.exit) { priorState.exit(this); }
Expand Down
10 changes: 5 additions & 5 deletions packages/ember-views/lib/mixins/view_support.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export default Mixin.create({
@public
*/
rerender() {
return this.currentState.rerender(this);
return this._currentState.rerender(this);
},

// ..........................................................
Expand Down Expand Up @@ -209,7 +209,7 @@ export default Mixin.create({
*/
$(sel) {
Ember.assert('You cannot access this.$() on a component with `tagName: \'\'` specified.', this.tagName !== '');
return this.currentState.$(this, sel);
return this._currentState.$(this, sel);
},

forEachChildView(callback) {
Expand Down Expand Up @@ -496,7 +496,7 @@ export default Mixin.create({
@private
*/
destroyElement() {
return this.currentState.destroyElement(this);
return this._currentState.destroyElement(this);
},

/**
Expand Down Expand Up @@ -713,7 +713,7 @@ export default Mixin.create({
@private
*/
handleEvent(eventName, evt) {
return this.currentState.handleEvent(this, eventName, evt);
return this._currentState.handleEvent(this, eventName, evt);
},

/**
Expand Down Expand Up @@ -765,7 +765,7 @@ export default Mixin.create({
_wrapAsScheduled(fn) {
var view = this;
var stateCheckedFn = function() {
view.currentState.invokeObserver(this, fn);
view._currentState.invokeObserver(this, fn);
};
var scheduledFn = function() {
run.scheduleOnce('render', this, stateCheckedFn);
Expand Down
4 changes: 2 additions & 2 deletions packages/ember-views/lib/views/core_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var CoreView = EmberObject.extend(Evented, ActionHandler, {
init() {
this._super.apply(this, arguments);
this._state = 'preRender';
this.currentState = this._states.preRender;
this._currentState = this._states.preRender;
this._isVisible = get(this, 'isVisible');

// Fallback for legacy cases where the view was created directly
Expand Down Expand Up @@ -108,7 +108,7 @@ var CoreView = EmberObject.extend(Evented, ActionHandler, {
destroy() {
if (!this._super(...arguments)) { return; }

this.currentState.cleanup(this);
this._currentState.cleanup(this);

// If the destroyingSubtreeForView property is not set but we have an
// associated render node, it means this view is being destroyed from user
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-views/lib/views/states/has_element.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ merge(hasElement, {
},

cleanup(view) {
view.currentState.destroyElement(view);
view._currentState.destroyElement(view);
},

// once the view is already in the DOM, destroying it removes it
Expand Down
7 changes: 7 additions & 0 deletions packages/ember-views/lib/views/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import AriaRoleSupport from 'ember-views/mixins/aria_role_support';
import VisibilitySupport from 'ember-views/mixins/visibility_support';
import CompatAttrsProxy from 'ember-views/compat/attrs-proxy';
import ViewMixin from 'ember-views/mixins/view_support';
import { deprecateProperty } from 'ember-metal/deprecate_property';

/**
@module ember
Expand Down Expand Up @@ -694,6 +695,12 @@ var View = CoreView.extend(
return View._classStringForValue(parsedPath.path, parsedPath.stream.value(), parsedPath.className, parsedPath.falsyClassName);
}
});

deprecateProperty(View.prototype, 'currentState', '_currentState', {
id: 'ember-view.current-state',
until: '2.3.0'
});

// jscs:enable validateIndentation

/*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import EmberView from 'ember-views/views/view';
import run from 'ember-metal/run_loop';

var view;

QUnit.module('views/view/current_state_deprecation', {
setup() {
view = EmberView.create();
},
teardown() {
run(view, 'destroy');
}
});

QUnit.test('deprecates when calling currentState', function() {
expect(2);

view = EmberView.create();

expectDeprecation(function() {
equal(view.currentState, view._currentState);
}, 'Usage of `currentState` is deprecated, use `_currentState` instead.');
});

QUnit.test('doesn\'t deprecate when calling _currentState', function() {
expect(1);

view = EmberView.create();
ok(view._currentState, '_currentState can be used without deprecation');
});
2 changes: 1 addition & 1 deletion packages/ember-views/tests/views/view/replace_in_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ QUnit.test('should move the view to the inDOM state after replacing', function()
view.replaceIn('#menu');
});

equal(view.currentState, view._states.inDOM, 'the view is in the inDOM state');
equal(view._currentState, view._states.inDOM, 'the view is in the inDOM state');
});

QUnit.module('EmberView - replaceIn() in a view hierarchy', {
Expand Down
3 changes: 1 addition & 2 deletions packages/ember-views/tests/views/view/view_lifecycle_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,9 @@ QUnit.test('trigger rerender on a view in the inDOM state keeps its state as inD
view.rerender();
});

equal(view.currentState, view._states.inDOM, 'the view is still in the inDOM state');
equal(view._currentState, view._states.inDOM, 'the view is still in the inDOM state');

run(function() {
view.destroy();
});
});

0 comments on commit 12d23bc

Please sign in to comment.