feat(BaseRequestOptions): add merge method to make copies of options

This commit is contained in:
Jeff Cross
2015-06-12 21:50:19 -07:00
parent ea27704ea9
commit 93596dff3f
2 changed files with 53 additions and 8 deletions

View File

@ -1,21 +1,34 @@
import {CONST_EXPR, CONST} from 'angular2/src/facade/lang';
import {CONST_EXPR, CONST, isPresent} from 'angular2/src/facade/lang';
import {Headers} from './headers';
import {URLSearchParams} from './url_search_params';
import {RequestModesOpts, RequestMethods, RequestCacheOpts, RequestCredentialsOpts} from './enums';
import {RequestOptions} from './interfaces';
import {Injectable} from 'angular2/di';
import {ListWrapper, StringMapWrapper} from 'angular2/src/facade/collection';
@Injectable()
export class BaseRequestOptions implements RequestOptions {
method: RequestMethods;
export class RequestOptionsClass {
method: RequestMethods = RequestMethods.GET;
headers: Headers;
body: URLSearchParams | FormData | string;
mode: RequestModesOpts;
mode: RequestModesOpts = RequestModesOpts.Cors;
credentials: RequestCredentialsOpts;
cache: RequestCacheOpts;
constructor({method, headers, body, mode, credentials,
cache}: RequestOptions = {method: RequestMethods.GET, mode: RequestModesOpts.Cors}) {
this.method = method;
this.headers = headers;
this.body = body;
this.mode = mode;
this.credentials = credentials;
this.cache = cache;
}
constructor() {
this.method = RequestMethods.GET;
this.mode = RequestModesOpts.Cors;
merge(opts: RequestOptions = {}): RequestOptionsClass {
return new RequestOptionsClass(StringMapWrapper.merge(this, opts));
}
}
@Injectable()
export class BaseRequestOptions extends RequestOptionsClass {
constructor() { super(); }
}