-
Notifications
You must be signed in to change notification settings - Fork 119
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
Param builders for building complex parameter objects #384
Comments
Having fluent builders would certainly help us bury more platform idiosyncrasies, so that alone is a win. import { search, queryBuilder } from '@esri/arcgis-rest-items';
// ability to construct a template that can later be refined...
// a sort of partial-application on an object graph
const texasWaterWebApps = queryBuilder()
.withAuth(myAuthFromSessionOrWherever)
.hasType('Web Mapping Application')
.withoutType('Web Map')
.hasTag('water')
.hasTag('texas')
.culture('en-us')
.hasKeyword('hubSolution')
.withoutKeyword('hubSolutionTemplate');
// later... given some user input...
const query = queryBuilder(texasWaterWebApps)
.search('waco');
return search(query).then(...) |
i think this is a great idea. |
I like this idea. I think it will be a bit challenging in TS. I wrote a fluent API for cedar and it was a lot of overloads juggling. Also, I do think there could be a little cognitive dissonance if most of the fns in the lib are stateless fns that return promises, and then there are a few fluent (stateful) builders. I wonder how this will interplay w/ #339 All that said, I think this will provide a valuable benefit to consumers of this library. |
@tomwayson @dbouwman I'm really interested in writing at least the first one of these for building a search Before I get too far into this though I know you both are (particularly @dbouwman) are huge FP fans. Fluent interfaces in TS would be super easy with classes but in keeping without goal of ideally NOT using classes and holding state in them I did some extra research.
I'm really leaning towards option 2 here. I think it will be the easiest option. In either case when To allow the builder not to have to warp EVERY param on the API (although ideally they should) we could allow an escape hatch in function QueryBuilder() {
var params = { q: "" , num: 10, start: 0};
return {
// the type for this is actually optional here but it might add some type safety
andTags(this: ReturnType<typeof QueryBuilder>, ...tags) {
params.q += tags.join(",");
return this;
},
toParams(additionalParams) {
return {...params, ...additionalParams};
}
};
}
const params = QueryBuilder()
.andTags("foo", "bar")
.andTags("baz")
.toParams({someOtherParamThatIsntWrapped: true});
console.log(params); |
this will be included in |
Reopening this to continue to track discussion of additional builders. |
Given that this library now has the capacity to do routing #382 and create feature services I want to put forward the idea of including some reasonable APIs for building the parameters objects like what I specced for https://github.com/Esri/esri-leaflet-routing/blob/master/Route.md and https://github.com/Esri/esri-leaflet-routing/blob/master/TravelArea.md. THis would make the job of building out the params or options objects much more reasonable for things like
IAddToServiceDefinitionRequestOptions
to wrap common use cases. For example:Opening this up for comment, @noahmulfinger @araedavis @tomwayson @dbouwman @jgravois.
The text was updated successfully, but these errors were encountered: