Skip to content
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

feat(): custom parameter #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/jsonpadding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
import 'src/jsonp_call.dart';
import 'dart:async';

Future<dynamic> jsonp(dynamic uri) => new JsonpCall(uri).call();
Future<dynamic> jsonp(dynamic uri, {String param}) =>
new JsonpCall(uri, param: param).call();

class Jsonp {
Future<dynamic> get(dynamic uri) => jsonp(uri);
final String param;

Jsonp({this.param});

Future<dynamic> get(dynamic uri, {String param}) =>
jsonp(uri, param: param ?? this.param);
}
6 changes: 4 additions & 2 deletions lib/src/jsonp_call.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ class JsonpCall {
final ScriptElement script = new ScriptElement();
final String callback = _createId();
Uri uri;
String _param = 'callback';

JsonpCall(dynamic uri) {
JsonpCall(dynamic uri, {String param}) {
_param = param ?? _param;
this.uri = _createUri(uri, callback);
}

Expand All @@ -36,7 +38,7 @@ class JsonpCall {
Uri _createUri(dynamic uri, String callback) {
uri = (uri is Uri) ? uri : Uri.parse(uri);
Map parameters = new Map.from(uri.queryParameters);
parameters['callback'] = callback;
parameters[_param] = callback;
return uri.replace(queryParameters: parameters);
}
}