• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

electron based twitter client


Commit MetaInfo

修訂c519ca8f3b6ed52763a1fe0dd121e9d35abd9a30 (tree)
時間2016-02-06 23:54:16
作者Hiromichi Matsushima <hylom@Hiro...>
CommiterHiromichi Matsushima

Log Message

add auto update TL with stream API

Change Summary

差異

--- a/main.js
+++ b/main.js
@@ -5,7 +5,7 @@ var BrowserWindow = require('browser-window');
55 var mainWindow = null;
66
77 function createWindow () {
8- mainWindow = new BrowserWindow({width: 800, height: 600});
8+ mainWindow = new BrowserWindow({width: 400, height: 800});
99 mainWindow.loadURL('file://' + __dirname + '/index.html');
1010
1111 mainWindow.on('closed', function() {
--- a/models.js
+++ b/models.js
@@ -9,4 +9,11 @@ exports.getHomeTimeline = function (callback) {
99 client.get('statuses/home_timeline', callback);
1010 };
1111
12-
12+exports.stream = function (callback) {
13+ client.stream('user', {}, function (stream) {
14+ stream.on('data', callback);
15+ stream.on('error', function(error) {
16+ throw error;
17+ });
18+ });
19+}
--- a/view.js
+++ b/view.js
@@ -10,12 +10,14 @@ function sprnkrViewMain () {
1010 var name = tweet.user.name + ' (@' + tweet.user.screen_name + ')';
1111 var timestamp = tweet.created_at;
1212 var text = tweet.text;
13- var content = name + ' ' + timestamp + '<br>' + text
13+ var content = '<div class="header"><span class="username">' + name + '</span><span class="timestamp">' + timestamp + '</span></div>';
14+ content += '<div class="body">'+ text + '</div>';
1415 var elem = $("<li>" + content + "</li>");
15- $("#sprnkr-items").append(elem);
16+ $("#sprnkr-items").prepend(elem);
1617 }
1718 tweetWriter.write = function (tweet) {
1819 if (util.isArray(tweet)) {
20+ tweet.reverse();
1921 tweet.forEach(this.put);
2022 } else {
2123 this.put(tweet);
@@ -24,13 +26,16 @@ function sprnkrViewMain () {
2426
2527 const remote = require('electron').remote;
2628 var models = remote.require('./models');
27- models.getHomeTimeline(renderTimeline);
29+ models.getHomeTimeline(initTimeline);
2830
29- function renderTimeline(err, tweets, resp) {
31+ function initTimeline(err, tweets, resp) {
3032 if (err) throw err;
3133 tweetWriter.write(tweets);
34+ models.stream(function(tweets) {
35+ tweetWriter.write(tweets);
36+ });
3237 };
38+
3339 }
3440
35-console.log("do main");
3641 sprnkrViewMain();