/* Client-side code for a chat application */
// Connect to socket.io
window.socket = io.connect('http://localhost');
// Set-up code in a Model
PostModel = Y.PostModel = Y.Base.create('postModel', Y.Model, [Y.ModelSync.Socket], {
root: '/posts'
}, {
ATTRS: {
id: '',
author: '',
email: '',
message: ''
}
});
// Set-up code in a View
PostView = Y.PostView = Y.Base.create('postView', Y.View, [], {
containerTemplate: '<li class="post-item" />',
template: Y.one('#blog-post-template').getContent(),
initializer: function () {
var model = this.get('model'),
self = this;
model.onSocket('delete', function (e) {
self.constructor.superclass.remove.call(self);
});
model.onSocket('update', function (e) {
this.setAttrs(e.data);
});
model.after('change', this.render, this);
}
// And so on
});
/* Server-side code for a chat application */
var server = app.listen(3000),
io = require('socket.io').listen(server),
db = new Collection();
io.sockets.on('connection', function (socket) {
socket.on('posts:update', function (data, callback) {
db.update(data);
socket.emit('posts/' + data.id + ':update', {data: data});
socket.broadcast.emit('posts/' + data.id + ':update', {data: data});
});
socket.on('posts:read', function (data, callback) {
socket.emit('posts:read', {data: db.toJSON()});
});
socket.on('posts:construct', function (data, callback) {
data = db.add(data);
socket.emit('posts:construct', {data: data});
socket.broadcast.emit('posts:construct', {data: data});
});
socket.on('posts:delete', function (data, callback) {
db.remove(data);
socket.emit('posts/' + data.id + ':delete');
socket.broadcast.emit('posts/' + data.id + ':delete');
});
});/home/y/libexec/ant/bin/ant all
Buildfile: build.xml
[echo] Starting Build For gallery-model-sync-socket
clean:
init:
[mkdir] Created dir: /home/y/var/builds/workspace/gallery/build_tmp/src/yui3-gallery/src/gallery-model-sync-socket/build_tmp
[echo] Starting Build For gallery-model-sync-socket
-lint-server:
[echo] Starting Build For gallery-model-sync-socket
-node:
[echo] For faster builds, install Node.js.
-concatdebug:
[copy] Copying 1 file to /home/y/var/builds/workspace/gallery/build_tmp/src/yui3-gallery/src/gallery-model-sync-socket/build_tmp/ant
[delete] Deleting directory /home/y/var/builds/workspace/gallery/build_tmp/src/yui3-gallery/src/gallery-model-sync-socket/build_tmp/ant
-registerdebug:
[copy] Copying 1 file to /home/y/var/builds/workspace/gallery/build_tmp/src/yui3-gallery/src/gallery-model-sync-socket/build_tmp
-prependdebug:
-appenddebug:
builddebug:
-createcore:
[copy] Copying 1 file to /home/y/var/builds/workspace/gallery/build_tmp/src/yui3-gallery/src/gallery-model-sync-socket/build_tmp
-loggerregex:
buildcore:
-rollupjs:
-concatskins:
-buildskins:
-rollupcss:
buildskins:
-buildlangs:
-rolluplangs:
buildlangs:
build:
minify:
[yuicompressor] Compressing /home/y/var/builds/workspace/gallery/build_tmp/src/yui3-gallery/src/gallery-model-sync-socket/build_tmp/gallery-model-sync-socket.js
[yuicompressor]
[yuicompressor] [WARNING] Try to use a single 'var' statement per scope.
[yuicompressor] window.socket||this.socket;} ---> var <--- event={type:type,global:globalType
[yuicompressor]
[yuicompressor] [WARNING] Try to use a single 'var' statement per scope.
[yuicompressor] window.socket||Y.socket;} ---> var <--- events=ioEvents[type];if(Y
[yuicompressor]
[yuicompressor] [WARNING] Try to use a single 'var' statement per scope.
[yuicompressor] &&isFunction(callback)){for( ---> var <--- i=0,len=events.length;
[yuicompressor]
[yuicompressor] [WARNING] Try to use a single 'var' statement per scope.
[yuicompressor] socket||Y.socket;}for( ---> var <--- socket in ioEvents){this.detachSocket(socket
[yuicompressor]
[yuicompressor] [WARNING] Try to use a single 'var' statement per scope.
[yuicompressor] action==="create")?"construct":action; ---> var <--- params=Y.mix(options,{req
[yuicompressor]
[yuicompressor] [WARNING] Try to use a single 'var' statement per scope.
[yuicompressor] .toJSON()||{};} ---> var <--- io=window.socket||Y.socket;
[yuicompressor]
[yuicompressor] [WARNING] The symbol self is declared but is apparently never used.
[yuicompressor] This code can probably be written in a more compact way.
[yuicompressor] ._getURL()+":"+type, ---> self <--- =this;if(isFunction(io))
[yuicompressor] Compressed to /home/y/var/builds/workspace/gallery/build_tmp/src/yui3-gallery/src/gallery-model-sync-socket/build_tmp/gallery-model-sync-socket-min.js
lint:
[echo] Using Rhino. Install nodejs to improve jslint speed, or skip with -Dlint.skip=true
[java] Running JSLint on : /home/y/var/builds/workspace/gallery/build_tmp/src/yui3-gallery/src/gallery-model-sync-socket/build_tmp/gallery-model-sync-socket.js
[java]
[java]
[java] 140, 31: Expected an assignment or function call and instead saw an expression.
[java] config || (config = {});
[java]
[java] 141, 54: Expected an assignment or function call and instead saw an expression.
[java] isValue(config.url) && (this.url = config.url);
[java]
[java] 250, 9: The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype.
[java] for (var socket in ioEvents) {
[java]
[java] 333, 13: 'data' is not defined.
[java] data = {};
[java]
[java] 338, 21: 'data' is not defined.
[java] data[k] = encodeURIComponent(v);
[java]
[java] 343, 28: 'data' is not defined.
[java] url = sub(url, data);
[java]
[java]
[java]
local:
deploybuild:
[copy] Copying 3 files to /home/y/var/builds/workspace/gallery/build_tmp/src/yui3-gallery/build/gallery-model-sync-socket
deployassets:
deployskins:
deploylang:
deploydocs:
deploy:
all:
BUILD SUCCESSFUL
Total time: 2 seconds
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info