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

Add deprecation for old usages of cachable and readOnly in CPs #9489

Merged

Conversation

cibernox
Copy link
Contributor

@cibernox cibernox commented Nov 4, 2014

  • Passing opts.cacheable to the constructor of ComputedProperty is deprecated
  • Passing opts.readOnly to the constructor of ComputedProperty is deprecated
  • Invoking cacheable in a computed property is preprecated.
  • Invoking readOnly with aany params in a computed property is deprecated.

-- UPDATE --

After reading #9290 and emberjs/rfcs#12, seems that this PR is the first step to make CP read only by default.

Steps done in this PR:

  • Raise deprecation warnings when passing cacheable or readOnly to the constructor. No extrictly necessary, but is not used anywhere in the code since 2012 and simplifies things.
  • Deprecate usage of cacheable() and readOnly(). Are the default.

Steps pending:

  • Modify CPs to work internally with setter and getters. A way of doing that gracefully without people even noticing it could be count the arity of the function passed to Ember.computed. If is arity <=1, create only a setter. If has arity > 1, assign the same function to getter and setter. Passing an object also works. No deprecations yet.
  • Deprecate passing functions with arity > 1. Recommend user {get, set} instead.
  • Implement logic in this RFC: Create writable and/or overridable and determina default values as explained in the code example above.
  • Deprecate all the things!
  • Ember 2.0. Delete all the things!

This steps don't need to happen in this PR. I fact I would merge things one step at a time.

@cibernox cibernox force-pushed the deprecate_cacheable_method_in_cps branch from 64de7e4 to c60c5c6 Compare November 4, 2014 14:07
@rwjblue
Copy link
Member

rwjblue commented Nov 4, 2014

Can you add a test that uses expectDeprecation to confirm this works as desired (deprecates when calling cacheable, but not when you don't).

Can you also deprecate passing opts.cacheable in the CP constructor (same area as your prior PR), and add tests to confirm deprecation scenarios?

@@ -145,6 +145,7 @@ var ComputedPropertyPrototype = ComputedProperty.prototype;
@chainable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be marked as @deprecated also.

@cibernox
Copy link
Contributor Author

cibernox commented Nov 4, 2014

I'm on it.

@cibernox cibernox force-pushed the deprecate_cacheable_method_in_cps branch 4 times, most recently from b08e76d to 9f48f03 Compare November 4, 2014 14:27
@cibernox
Copy link
Contributor Author

cibernox commented Nov 4, 2014

All done.

You mentioned in the former PR that readOnly should be deprecated too. I can deprecate passing opts.readOnly in the constructor, but there is no equivalent of volatile for readOnly. I think I wouldn't deprecate it.

Because you can pass readOnly(false). I can deprecate to pass any value to readOnly though.

@cibernox
Copy link
Contributor Author

cibernox commented Nov 4, 2014

Forget my last comment. I misread your comment in the last PR.

@@ -120,7 +120,8 @@ function ComputedProperty(func, opts) {
this._suspended = undefined;
this._meta = undefined;

this._cacheable = (opts && opts.cacheable !== undefined) ? opts.cacheable : true;
Ember.deprecate("Passing opts.cacheable to the CP constructor is deprecated. Invoke `volatile()` on the CP instead.", !opts || !opts.hasOwnProperty('cacheable'));
this._cacheable = (opts && opts.cacheable !== undefined) ? opts.cacheable : true; // TODO: Set alwats to `true` once this deprecation is gone.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/alwats/always/

@cibernox cibernox force-pushed the deprecate_cacheable_method_in_cps branch from 9f48f03 to 3815441 Compare November 4, 2014 14:48
@cibernox cibernox changed the title Deprecate ComputedProperty.cacheable(). Add deprecation for old usages of cachable and readOnly in CPs Nov 4, 2014
@cibernox
Copy link
Contributor Author

cibernox commented Nov 4, 2014

Added readOnly deprecation too.

@rwjblue
Copy link
Member

rwjblue commented Nov 4, 2014

There are a few failures, when running with this query-string.

@cibernox
Copy link
Contributor Author

cibernox commented Nov 4, 2014

Fixed. Now I invoke readOnly instead of passing the option on the constructor. The readOnly method is inherited form the CP prototype, as some other methods.

Should I rebase?

@stefanpenner
Copy link
Member

@krisselden r?

@rwjblue
Copy link
Member

rwjblue commented Nov 4, 2014

@cibernox - Yes, if you could squash and rebase, that would be great.

@cibernox cibernox force-pushed the deprecate_cacheable_method_in_cps branch from 904dfc1 to c56e38c Compare November 4, 2014 15:47
@cibernox
Copy link
Contributor Author

cibernox commented Nov 4, 2014

Rebased. Done here.

@rwjblue
Copy link
Member

rwjblue commented Nov 5, 2014

@cibernox - Thank you. I think we are waiting for @krisselden to have a chance to review before merging.

@cibernox cibernox mentioned this pull request Nov 7, 2014
4 tasks
@stefanpenner stefanpenner self-assigned this Nov 7, 2014
@benlesh
Copy link
Contributor

benlesh commented Nov 8, 2014

👍

@rwjblue
Copy link
Member

rwjblue commented Nov 9, 2014

This seems good to me.

@stefanpenner / @krisselden - Any tweaks or objections?

@cibernox
Copy link
Contributor Author

cibernox commented Nov 9, 2014

For the record, I have implemented emberjs/rfcs#11 on top of this.
Only two failing tests involving super. I'll ask for help later in IRC

@cibernox cibernox mentioned this pull request Nov 10, 2014
8 tasks
@cibernox
Copy link
Contributor Author

@krisselden / @stefanpenner Ping here. #9527 is done and based on this one.

@cibernox cibernox force-pushed the deprecate_cacheable_method_in_cps branch from c56e38c to 56f1b57 Compare November 13, 2014 01:10
@cibernox
Copy link
Contributor Author

Rebased

@stefanpenner
Copy link
Member

so far looks good.

@krisselden your eyes would be good

@cibernox
Copy link
Contributor Author

Another ping to @krisselden !

@stefanpenner
Copy link
Member

I have PM'd him aswell.

proof of receipt:
screenshot 2014-11-17 17 30 14

@cibernox
Copy link
Contributor Author

Thanks!

@cibernox
Copy link
Contributor Author

@krisselden you're the next

*/
ComputedPropertyPrototype.cacheable = function(aFlag) {
Ember.deprecate('ComputedProperty.cacheable() is deprecated. All computed properties are cacheable by default. Use `.volatile()` if you want to mark a computed property as not cacheable.');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.volatile is more like manual, it may prevent the internal CP caching, but it has no effect on downstream caching that happens in the view layer for example. It is generally used for properties that are manually notified and delegated, like array.length. It really should be an extremely rare occurrence in an app.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what do you suggest then? Not mention volatile at all?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect he would prefer you don't mention it at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ywimc

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cibernox lol, i see we have driven you to insanity with our slowness. Sorry, we will not let this happen again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

insane? me?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@cibernox cibernox force-pushed the deprecate_cacheable_method_in_cps branch from 56f1b57 to bb8d206 Compare November 25, 2014 00:06
* Passing opts.cacheable to the constructor of ComputedProperty is deprecated
* Passing opts.readOnly to the constructor of ComputedProperty is deprecated
* Invoking `cacheable` in a computed property is preprecated.
* Invoking `readOnly` with aany params in a computed property is deprecated.
* Make InjectedProperty inherit `readOnly` from CPs prototype
@cibernox cibernox force-pushed the deprecate_cacheable_method_in_cps branch from bb8d206 to dd15598 Compare November 25, 2014 00:21
@cibernox
Copy link
Contributor Author

I would say that NOW its ready to merge.

@cibernox
Copy link
Contributor Author

cibernox commented Dec 1, 2014

@stefanpenner ping!

stefanpenner added a commit that referenced this pull request Dec 1, 2014
Add deprecation for old usages of cachable and readOnly in CPs
@stefanpenner stefanpenner merged commit 29bbb59 into emberjs:master Dec 1, 2014
@stefanpenner
Copy link
Member

👍 sorry, i have meant to review this sooner but i have been sick in bed for the last few days.

@cibernox cibernox deleted the deprecate_cacheable_method_in_cps branch December 1, 2014 23:50
@cibernox
Copy link
Contributor Author

cibernox commented Dec 1, 2014

Don't worry :shipit:

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

Successfully merging this pull request may close these issues.

5 participants