|
1 | | -import {CONST_EXPR, CONST} from 'angular2/src/facade/lang'; |
| 1 | +import {CONST_EXPR, CONST, isPresent} from 'angular2/src/facade/lang'; |
2 | 2 | import {Headers} from './headers'; |
3 | 3 | import {URLSearchParams} from './url_search_params'; |
4 | 4 | import {RequestModesOpts, RequestMethods, RequestCacheOpts, RequestCredentialsOpts} from './enums'; |
5 | 5 | import {RequestOptions} from './interfaces'; |
6 | 6 | import {Injectable} from 'angular2/di'; |
| 7 | +import {ListWrapper, StringMapWrapper} from 'angular2/src/facade/collection'; |
7 | 8 |
|
8 | | -@Injectable() |
9 | | -export class BaseRequestOptions implements RequestOptions { |
10 | | - method: RequestMethods; |
| 9 | +export class RequestOptionsClass { |
| 10 | + method: RequestMethods = RequestMethods.GET; |
11 | 11 | headers: Headers; |
12 | 12 | body: URLSearchParams | FormData | string; |
13 | | - mode: RequestModesOpts; |
| 13 | + mode: RequestModesOpts = RequestModesOpts.Cors; |
14 | 14 | credentials: RequestCredentialsOpts; |
15 | 15 | cache: RequestCacheOpts; |
| 16 | + constructor({method, headers, body, mode, credentials, |
| 17 | + cache}: RequestOptions = {method: RequestMethods.GET, mode: RequestModesOpts.Cors}) { |
| 18 | + this.method = method; |
| 19 | + this.headers = headers; |
| 20 | + this.body = body; |
| 21 | + this.mode = mode; |
| 22 | + this.credentials = credentials; |
| 23 | + this.cache = cache; |
| 24 | + } |
16 | 25 |
|
17 | | - constructor() { |
18 | | - this.method = RequestMethods.GET; |
19 | | - this.mode = RequestModesOpts.Cors; |
| 26 | + merge(opts: RequestOptions = {}): RequestOptionsClass { |
| 27 | + return new RequestOptionsClass(StringMapWrapper.merge(this, opts)); |
20 | 28 | } |
21 | 29 | } |
| 30 | + |
| 31 | +@Injectable() |
| 32 | +export class BaseRequestOptions extends RequestOptionsClass { |
| 33 | + constructor() { super(); } |
| 34 | +} |
0 commit comments