Switch all methods to use a single options object
See original GitHub issueBetween https://github.com/Esri/arcgis-rest-js/issues/73 and https://github.com/Esri/arcgis-rest-js/pull/74 it seems we are struggling to figure out the right order of options and how to pass commonly used things like owner
and portal
. I am going to suggest the following:
- Every method accepts a single
options
object. - That object is strictly typed and inherits from
IRequestOptions
or another options interface that inherits fromIRequestOptions
. request
now looks likeinterface IRequestOptions () { url: string; params?: IParams; httpMethod?: HTTPMethods; authentication?: IAuthenticationManager; fetch?: (input: RequestInfo, init?: RequestInit) => Promise<Response>; } request(options: IRequestOptions) { /** request **/ }
- Methods that wrap
request
are now implemented like:interface IReassignItemOptions extends IRequestOptions() { /** * `url` is not allowed in `IReassignItemOptions`. Use `portal` instead. */ url: void; itemId: string; owner: string; newOwner: string; newFolder?: string; portal?: string; } reassignItem(options: IReassignItemOptions) { /* * `portal` and `currentOwner` can default to `options.authentication.username` * and `options.authentication.portal` or be overridden by the `portal` and `owner` options. */ }
portal
should be removed fromIRequestOptions
since not all methods require it https://github.com/Esri/arcgis-rest-js/blob/master/packages/arcgis-rest-request/src/request.ts#L51.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Multiple arguments vs. options object - javascript
When creating a JavaScript function with multiple arguments, I am always confronted with this choice: pass a list of arguments vs. pass an...
Read more >How to use options object in functions? | by Arek Jaworski
We can easily change all our functions to use options object. Let's rewrite function bar: function bar (options) { const { param1, param2,...
Read more >What are JavaScript options objects?
In JavaScript, options objects are a common pattern for passing arguments into a function. This article explains how they work and why using...
Read more >Replacing switch statements with Object literals
In many programming languages, the switch statement exists - but should ... We use Objects all the time, either as constructors or literals....
Read more >Future Proof Your Methods With Options Objects
Having methods that takes a lot of arguments can be a real pain. ... The answer is simple – Use one options object...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m all for what @tomwayson said about keeping URL as its own param in https://github.com/Esri/arcgis-rest-js/issues/75#issuecomment-349775514. I updated my original proposal to match.
resolved via #78