Comments (11)
Well, this is made to deprecate your API, so the premise is you would know what your own API looks like.
But I see you are deprecating the accessing/setting of a property on a general options
object. I can certainly think about the support. I'd be interested in seeing how you're trying to use it so I can make sure I come up with the correct solution, as just making it not error for the above may seem to work, but there could possibly be a new kind of API that's even easier to do what you're trying.
If you cannot link to an example since it's not open source, you can always paste example code in here. Basically, to me, it seems weird to want to deprecate a property on an options
object, but perhaps you use it in a different way than I ever have.
from nodejs-depd.
P.S. The reason that function requires the property to exist, is because for us to properly re-define it, we have to know if it's configurable and if it's enumerable.
from nodejs-depd.
ok , because the object is optional argument. here it is: https://github.com/snowyu/level-subkey/blob/master/shell.js#L79
from nodejs-depd.
Ok. I think you are using the API incorrectly. To me, it looks like what you want for that line is actually this:
if (opts.prefix) deprecate('prefix option, use `path` instead.')
from nodejs-depd.
deprecate.property
does not display a message to the user, rather it sets up the property to print a deprecation when the user eventually tries to get or set that property. Your code when immediately accesses the property on the next line, making it look like you are using the right API :)
from nodejs-depd.
Got it. the js is very flexible script language, I can not compel developer to use a specified Options object like java. IMO most properties on javascript are just in a simple json object. so deprecate.property seldom useful. On java it is useful enough.
btw, I am too lazy to type the check code in deprecate statement repeatedly.
from nodejs-depd.
deprecate.property
is to deprecate properties your users are going to access, not properties in objects that users are going to pass into your code. I hope that makes it clear what the difference is.
In the code you linked to. if you removed the line
if (opts.prefix && !opts.path) opts.path = opts.prefix
then you would see how the deprecation message from deprecate.property
would no longer appear, because it's the wrong API for what you're trying to do is all. To deprecate things on incoming objects you just use the deprecate(msg)
API and not the others.
from nodejs-depd.
Basically, your code should look like this:
if (opts.prefix) {
deprecate('prefix option, use `path` instead.')
if (!opts.path) opts.path = opts.prefix
}
from nodejs-depd.
I have wrapped it with this:
function deprecatedPrefixOption(options) {
if (options.prefix) {
deprecate('prefix option, use `path` instead.')
if (!options.path) options.path = options.prefix
delete options.prefix
}
}
But this can be extracted as a new feature to do, what is a perfect name?
function deprecate.assignProperty(object, deprecatedProp, currentProp) {
if (object[deprecatedProp]) {
deprecate(deprecatedProp+'property, use `'+currentProp+'` instead.')
if (!object[currentProp]) object[currentProp] = object[deprecatedProp]
delete object[deprecatedProp]
}
}
from nodejs-depd.
That API is out of the scope of this module, unfortunately, as it's extremely opinionated in how you're supposed to use objects as options
, including the fact that all you're doing is changing the name of a property on an incoming object. Next thing you know, I'll need to extend it because people want the currentProp
to depend on the contents of the deprecated property's value, then they'll want to support the deprecated property's value being 0
, undefined
, or null
. This can go on forever...
Your helper also won't function correctly, because the call location of your deprecate
function is required to be unique in your file for each instance, otherwise sometimes the warnings may not appear to the user.
from nodejs-depd.
Yes, the assignProperty helper function is just for assigning the current property to a depreacted property. even they do not wanna delete the deprecatedProp. Enhance a good API is not easy thing.
Pardon? your means in the example code, should use this instead of deprecate function.
from nodejs-depd.
Related Issues (20)
- Stack trace api differences when in strict mode causing TypeErrors HOT 25
- Fail gracefully in unsupported browsers HOT 15
- Drop eval usage HOT 21
- line info is not help HOT 8
- Cannot redefine property: callSiteToString HOT 2
- Call-site calculation does not fail gracefully when Stack information is unavailable HOT 14
- Call site calculation fails when importing an esm'ed package that imports sequelize internally HOT 14
- Respect --no-deprecation and process.noDeprecation HOT 17
- TypeError: eval is not a function HOT 8
- Why is this library overwriting Error type? HOT 5
- Turkish Language Problem HOT 2
- Incopatibile with --enable-source-maps node 12 option HOT 7
- (!) Use of eval is strongly discouraged, rollup HOT 1
- compatibility with Node.js' source-map implementation HOT 12
- please rewrite nodejs-depd with modern syntax HOT 1
- Compatibility with --disallow-code-generation-from-strings HOT 9
- Use of eval() is strongly discouraged, as it poses security risks HOT 9
- Calling `process.cwd()` from index.js can be problematic HOT 4
- callSite.getFileName() is not Function HOT 5
- `callSite.getFileName` is not a function HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nodejs-depd.