Skip to content

Commit 777415f

Browse files
committed
Update
1 parent c9c9b04 commit 777415f

12 files changed

+29
-30
lines changed

example/web/scripts/script.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import 'dart:html';
2-
import 'dart:json';
2+
import 'dart:convert';
33

44
import 'package:start/socket.dart';
55

lib/socket.dart

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
library Start_Socket;
2-
31
import 'dart:html';
42
import 'dart:async';
53

@@ -15,7 +13,7 @@ class Socket implements SocketBase {
1513
_messages = _messageController.stream.asBroadcastStream();
1614
_ws = new WebSocket(url);
1715
_ws.onMessage.listen((e) {
18-
var msg = new Message.fromPacket(e.data);
16+
var msg = new Message(e.data);
1917
_messageController.add(msg);
2018
});
2119
}
@@ -36,4 +34,4 @@ class Socket implements SocketBase {
3634
void close([int status, String reason]) {
3735
_ws.close(status, reason);
3836
}
39-
}
37+
}

lib/src/message.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
library start_message;
22

3-
import 'dart:json' as Json;
3+
import 'dart:convert';
44

55
class Message {
66
String name;
@@ -18,7 +18,7 @@ class Message {
1818
var data = null;
1919

2020
if (parts.length > 1 && !parts[1].isEmpty) {
21-
data = Json.parse(parts.sublist(1).join(':'));
21+
data = JSON.decode(parts.sublist(1).join(':'));
2222
}
2323

2424
return new Message(name, data);
@@ -30,6 +30,6 @@ class Message {
3030
if (data == null) {
3131
return name;
3232
}
33-
return '$name:${Json.stringify(data)}';
33+
return '$name:${JSON.encode(data)}';
3434
}
3535
}

lib/src/response.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,15 @@ class Response {
8888
}
8989

9090
json(data) {
91-
if (data is Map) {
92-
data = Json.stringify(data);
91+
if (data is Map || data is List) {
92+
data = JSON.encode(data);
9393
}
9494
send(data);
9595
}
9696

9797
jsonp(String name, data) {
9898
if (data is Map) {
99-
data = Json.stringify(data);
99+
data = JSON.encode(data);
100100
}
101101
send("$name('$data');");
102102
}

lib/src/route.dart

+6-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,12 @@ class Route {
6363
}
6464

6565
var keys = [];
66+
67+
if (!strict) {
68+
path += '/?';
69+
}
6670

67-
path = path.concat(strict ? '' : '/?')
68-
.replaceAllMapped(new RegExp(r'(\.)?:(\w+)(\?)?'), (Match placeholder) {
71+
path = path.replaceAllMapped(new RegExp(r'(\.)?:(\w+)(\?)?'), (Match placeholder) {
6972
var replace = new StringBuffer('(?:');
7073

7174
if (placeholder[1] != null) {
@@ -98,4 +101,4 @@ class Route {
98101
}
99102
return params;
100103
}
101-
}
104+
}

lib/src/server.dart

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ class Server {
1515
}
1616

1717
Future<Server> listen(String host, num port) {
18-
19-
return HttpServer.bind(host, port).then((server) {
20-
18+
return HttpServer.bind(host, port).then((HttpServer server){
2119
_server = server;
2220
_server.listen((HttpRequest req) {
2321
_routes.firstWhere((Route route) => route.match(req),

lib/src/socket.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Socket implements SocketBase {
99
Socket(this._ws) {
1010
_messages = _messageController.stream.asBroadcastStream();
1111
_ws.listen((data) {
12-
var msg = new Message.fromPacket(data);
12+
var msg = new Message(data);
1313
_messageController.add(msg);
1414
},
1515
onDone: () {

lib/start.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ library start;
22

33
import 'dart:io' hide Socket;
44
import 'dart:async';
5-
import 'dart:json' as Json;
5+
import 'dart:convert';
66
import 'dart:mirrors';
77

88
import 'src/socket_base.dart';

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: start
2-
version: 0.0.9
2+
version: 0.0.9+2
33
author: Yehor Lvivski <[email protected]>
44
description: Sinatra inspired Web framework
55
homepage: http://github.com/lvivski/start

test/browser/start_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
library start_test;
22

3-
import 'dart:json';
3+
import 'dart:convert';
44
import 'dart:html';
55

66
import 'package:unittest/unittest.dart';

test/message_test.dart

+8-8
Original file line numberDiff line numberDiff line change
@@ -28,55 +28,55 @@ message_tests() {
2828
"stuff":123,
2929
"other":"test"
3030
};
31-
Message msg = new Message.fromPacket("test:${stringify(data)}");
31+
Message msg = new Message.fromPacket("test:${JSON.encode(data)}");
3232

3333
expect(msg.name, equals("test"));
3434
expect(msg.data, equals(data));
3535
});
3636

3737
test("parses named message with List for data", () {
3838
List data = [1, 2, 3];
39-
Message msg = new Message.fromPacket("test:${stringify(data)}");
39+
Message msg = new Message.fromPacket("test:${JSON.encode(data)}");
4040

4141
expect(msg.name, equals("test"));
4242
expect(msg.data, equals(data));
4343
});
4444

4545
test("parses named message with bool for data", () {
4646
bool data = true;
47-
Message msg = new Message.fromPacket("test:${stringify(data)}");
47+
Message msg = new Message.fromPacket("test:${JSON.encode(data)}");
4848

4949
expect(msg.name, equals("test"));
5050
expect(msg.data, equals(data));
5151
});
5252

5353
test("parses named message with String for data", () {
5454
String data = "abc123";
55-
Message msg = new Message.fromPacket("test:${stringify(data)}");
55+
Message msg = new Message.fromPacket("test:${JSON.encode(data)}");
5656

5757
expect(msg.name, equals("test"));
5858
expect(msg.data, equals(data));
5959
});
6060

6161
test("parses named message with String containing colon for data", () {
6262
String data = "a:b:c";
63-
Message msg = new Message.fromPacket("test:${stringify(data)}");
63+
Message msg = new Message.fromPacket("test:${JSON.encode(data)}");
6464

6565
expect(msg.name, equals("test"));
6666
expect(msg.data, equals(data));
6767
});
6868

6969
test("parses named message with int for data", () {
7070
int data = 123;
71-
Message msg = new Message.fromPacket("test:${stringify(data)}");
71+
Message msg = new Message.fromPacket("test:${JSON.encode(data)}");
7272

7373
expect(msg.name, equals("test"));
7474
expect(msg.data, equals(data));
7575
});
7676

7777
test("parses named message with double for data", () {
7878
double data = 123.45;
79-
Message msg = new Message.fromPacket("test:${stringify(data)}");
79+
Message msg = new Message.fromPacket("test:${JSON.encode(data)}");
8080

8181
expect(msg.name, equals("test"));
8282
expect(msg.data, equals(data));
@@ -87,7 +87,7 @@ message_tests() {
8787
"stuff":123,
8888
"other":"test"
8989
};
90-
Message msg = new Message.fromPacket(":${stringify(data)}");
90+
Message msg = new Message.fromPacket(":${JSON.encode(data)}");
9191

9292
expect(msg.name, equals(""));
9393
expect(msg.data, equals(data));

test/start_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
library start_test;
22

3-
import 'dart:json';
3+
import 'dart:convert';
44
import 'dart:io' hide Socket;
55

66
import 'package:unittest/unittest.dart';

0 commit comments

Comments
 (0)