question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Switch all methods to use a single options object

See original GitHub issue

Between 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:

  1. Every method accepts a single options object.
  2. That object is strictly typed and inherits from IRequestOptions or another options interface that inherits from IRequestOptions.
  3. request now looks like
    interface IRequestOptions () {
      url: string;
      params?: IParams;
      httpMethod?: HTTPMethods;
      authentication?: IAuthenticationManager;
      fetch?: (input: RequestInfo, init?: RequestInit) => Promise<Response>;
    }
    
    request(options: IRequestOptions) {
      /** request **/
    }
    
  4. 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.
       */
    }
    
  5. portal should be removed from IRequestOptions 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:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
patrickarltcommented, Dec 6, 2017

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.

0reactions
jgravoiscommented, Dec 20, 2017

resolved via #78

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found