On Github bunopus / presentation-dart
Powered by
//get data from server let comments = api.getComments();
/** * @typedef Comment * @type Object * @property {Author} Name of the commenter */ /** * Used to collect comments from server * @public * @returns {[Comment]} Function returns array * of comments object */ function getComments(){
var comments = api.getComments(); some_internal_storage.push(comments); //... comments.push({id:'separator'}); showComments(comments);
import 'dart:html'; import 'dart:convert'; class CommentsService { dynamic getComments() { return HttpRequest.request("api/comments", method: "GET").then((result) { return JSON.decode(result.responseText); }); } }
class Comment { String description; String author; String avatarUrl; DateTime postedAt; }
Future<List<Comment>> getComments() { return HttpRequest.request("api/comments", method: "GET").then((HttpRequest result) { var raw = JSON.decode(result.responseText); return raw.map((Map rawComment) => new Comment.fromMap(rawComment)); }); }
//... .then((HttpRequest result) { /* some code */ }) //...
//... .then((HttpRequest result) { /* some code */ }) .catchError(handle401Error, test: (e) => e is NotAuthenticatedException) //...
//... .then((HttpRequest result) { /* some code */ }). .catchError(handle401Error, test: (e) => e is NotAuthenticatedException) .whenComplete(closeSocketOrServer); //...
Future<List<Comment>> getComments() { return HttpRequest.request("api/comments", method: "GET").then((HttpRequest result) { var raw = JSON.decode(result.responseText); return raw.map((Map rawComment) => new Comment.fromMap(rawComment)); }).catchError((Error e){ print(e); throw e; }); }
List<Comment> sortAndGetTopComments (List<Comment> comments, {int count: 5}) { return comments ..sort((a, b) => return a.postedAt.compareTo(b.postedAt) ) ..sublist(0, count); }
abstract class Entity { String author; String avatarUrl; DateTime postedAt; }
class Comment extends Entity { String description; }
abstract class Serializable { String serialize(); } class Comment extends Entity implements Serializable { String description; String serialize() { //... }
abstract class Entity { //... String toString(); } class Comment extends Entity { //... @override String toString() { //... }
class DateFormatter { String formatDate(DateTime d){ var formatter = new DateFormat('yyyy-MM-dd hh:mm'); return formatter.format(d); } } class Comment extends Entity with DateFormatter { //... @override String toString() { //... var stringedDate = formatDate(postedAt); } }
abstract class CommentsService { final StreamController<Comment> _controller = new StreamController(); Stream<Comment> get stream => _controller.stream; // some polling mechanism poll() { //... var comment = getComment(); _controller.add(comment); //... } }
service.stream.listen((Comment comment){ //... }); //and more! .where(bool test(T event)) .map(convert(T event)) .expand(Iterable expand(T element) .take(int count) .skip(int count) .takeWhile(bool test(T element)) .skipWhile(bool test(T element)) .transform(StreamTransformer streamTransformer),>
- Follow me: @bunopus - : @wriketeam - Slides & info: https://goo.gl/THnu3U