Skip to content

Commit e6b0200

Browse files
authored
Allow const ctor (#45)
1 parent e8479e1 commit e6b0200

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Added
9+
- `JsonApiClient` has `const` constructor
10+
11+
## [1.0.1] - 2019-04-05
12+
### Fixed
13+
- Bumped the dependencies versions due to a bug in `json_api_document`.
814

915
## [1.0.1] - 2019-04-05
1016
### Changed
@@ -61,7 +67,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6167
- Client: fetch resources, collections, related resources and relationships
6268

6369
[Unreleased]: https://github.com/f3ath/json-api-dart/compare/1.0.1...HEAD
64-
[1.0.1]: https://github.com/f3ath/json-api-dart/compare/0.6.0...1.0.0
70+
[1.0.1]: https://github.com/f3ath/json-api-dart/compare/1.0.0...1.0.1
6571
[1.0.0]: https://github.com/f3ath/json-api-dart/compare/0.6.0...1.0.0
6672
[0.6.0]: https://github.com/f3ath/json-api-dart/compare/0.5.0...0.6.0
6773
[0.5.0]: https://github.com/f3ath/json-api-dart/compare/0.4.0...0.5.0

lib/src/client.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import 'dart:async';
22
import 'dart:convert';
33

44
import 'package:http/http.dart' as http;
5+
import 'package:json_api/src/nullable.dart';
56
import 'package:json_api/src/response.dart';
67
import 'package:json_api/src/status_code.dart';
7-
import 'package:json_api/src/nullable.dart';
88
import 'package:json_api_document/json_api_document.dart';
99
import 'package:json_api_document/parser.dart';
1010

@@ -16,14 +16,14 @@ typedef http.Client HttpClientFactory();
1616
class JsonApiClient {
1717
static const contentType = 'application/vnd.api+json';
1818

19-
JsonApiParser _parser = const JsonApiParser();
19+
final JsonApiParser _parser = const JsonApiParser();
2020

2121
final HttpClientFactory _factory;
2222

2323
/// JSON:API client uses Dart's native Http Client internally.
2424
/// To customize its behavior you can pass the [factory] function.
25-
JsonApiClient({HttpClientFactory factory})
26-
: _factory = factory ?? (() => http.Client());
25+
const JsonApiClient({HttpClientFactory factory})
26+
: _factory = factory ?? _defaultFactory;
2727

2828
/// Fetches a resource collection by sending a GET request to the [uri].
2929
/// Use [headers] to pass extra HTTP headers.
@@ -194,3 +194,5 @@ class JsonApiClient {
194194
}
195195
}
196196
}
197+
198+
http.Client _defaultFactory() => http.Client();

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ dependencies:
88
collection: "^1.14.11"
99
http: "^0.12.0"
1010
dev_dependencies:
11-
json_api_server: "^0.0.1"
11+
json_api_server: "0.0.2"
1212
json_matcher: "^0.2.3"
1313
stream_channel: "^1.6.8"
1414
test: "^1.6.1"

0 commit comments

Comments
 (0)