mirror of
https://github.com/zhigang1992/deployd.git
synced 2026-01-12 22:46:42 +08:00
Added dpd.once, off, onConnect, socket functions
Test app should no longer have expected failures
This commit is contained in:
@@ -3,6 +3,10 @@
|
||||
## 0.6.8
|
||||
|
||||
- Fixed CORS incorrectly requiring a referer header
|
||||
- Added `dpd.once(name, fn)` function to execute a realtime handler exactly once
|
||||
- Added `dpd.off(name, [fn])` function to remove a realtime handler
|
||||
- Added `dpd.onConnect(fn)` function to listen for the built-in `connect` event. (Sugar for `dpd.once('connect', fn)`)
|
||||
- Added `dpd.socket` property to provide direct access to socket.io.
|
||||
|
||||
## 0.6.7
|
||||
|
||||
@@ -13,7 +17,7 @@
|
||||
- Fixed bugs preventing events from being `emit()`ed to users in certain connection states
|
||||
- Fixed bug where boolean query values (?bool=true) were not treated as booleans
|
||||
- Fixed unnecessary error when parsing JSON body
|
||||
- Added more intelegent body parsing
|
||||
- Added more intelligent body parsing
|
||||
- Added `changed()` method in collection events
|
||||
- Added `previous` object in collection events
|
||||
- Fixed `dpd showkey` prompt for missing keys.json
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
"lastsemic": true,
|
||||
"laxbreak": true,
|
||||
"strict": false,
|
||||
"eqnull": true,
|
||||
|
||||
"undef": true,
|
||||
"browser": true,
|
||||
|
||||
22
clib/dpd.js
22
clib/dpd.js
@@ -272,5 +272,27 @@
|
||||
socket.on.apply(socket, arguments);
|
||||
};
|
||||
|
||||
window.dpd.once = function(name, fn) {
|
||||
var _fn = function() {
|
||||
socket.removeListener(name, _fn);
|
||||
fn.apply(this, arguments);
|
||||
};
|
||||
socket.on(name, _fn);
|
||||
};
|
||||
|
||||
window.dpd.off = function(name, fn) {
|
||||
if (fn == null) {
|
||||
socket.removeAllListeners(name);
|
||||
} else {
|
||||
socket.removeListener(name, fn);
|
||||
}
|
||||
};
|
||||
|
||||
window.dpd.onConnect = function(fn) {
|
||||
window.dpd.once('connect', fn);
|
||||
};
|
||||
|
||||
window.dpd.socket = socket;
|
||||
|
||||
|
||||
})();
|
||||
@@ -85,6 +85,12 @@ ClientLib.prototype.generateResource = function(r, res) {
|
||||
res.write('dpd.' + jsName + '.on = function(ev, fn) {\n');
|
||||
res.write(' return dpd.on("' + r.path.replace('/', '') + '" + ":" + ev, fn);\n');
|
||||
res.write('}\n');
|
||||
res.write('dpd.' + jsName + '.once = function(ev, fn) {\n');
|
||||
res.write(' return dpd.once("' + r.path.replace('/', '') + '" + ":" + ev, fn);\n');
|
||||
res.write('}\n');
|
||||
res.write('dpd.' + jsName + '.off = function(ev, fn) {\n');
|
||||
res.write(' return dpd.off("' + r.path.replace('/', '') + '" + ":" + ev, fn);\n');
|
||||
res.write('}\n');
|
||||
}
|
||||
|
||||
if(r.external) {
|
||||
|
||||
@@ -19,8 +19,9 @@
|
||||
<div id="mocha"></div>
|
||||
<script>
|
||||
expect = chai.expect;
|
||||
|
||||
mocha.run();
|
||||
dpd.onConnect(function() {
|
||||
mocha.run();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -8,7 +8,7 @@ describe('Collection', function() {
|
||||
describe('dpd.on("createTodo", fn)', function() {
|
||||
it('should respond to a realtime event', function(done) {
|
||||
this.timeout(1500);
|
||||
dpd.on('createTodo', function(todo) {
|
||||
dpd.once('createTodo', function(todo) {
|
||||
expect(todo).to.exist;
|
||||
expect(todo.title).to.equal('$REALTIME');
|
||||
done();
|
||||
@@ -20,7 +20,7 @@ describe('Collection', function() {
|
||||
|
||||
describe('dpd.on("createTodo2", fn)', function() {
|
||||
it('should respond to a realtime event without a parameter', function(done) {
|
||||
dpd.on('createTodo2', function(todo) {
|
||||
dpd.once('createTodo2', function(todo) {
|
||||
expect(todo).to.not.exist;
|
||||
done();
|
||||
});
|
||||
@@ -31,7 +31,7 @@ describe('Collection', function() {
|
||||
|
||||
describe('dpd.todos.on("changed", fn)', function() {
|
||||
it('should respond to the built-in changed event on post', function(done) {
|
||||
dpd.todos.on('changed', function() {
|
||||
dpd.todos.once('changed', function() {
|
||||
done();
|
||||
});
|
||||
|
||||
@@ -40,7 +40,7 @@ describe('Collection', function() {
|
||||
|
||||
it('should respond to the built-in changed event on put', function(done) {
|
||||
dpd.todos.post({title: 'changed - create'}, function(item) {
|
||||
dpd.todos.on('changed', function() {
|
||||
dpd.todos.once('changed', function() {
|
||||
done();
|
||||
});
|
||||
|
||||
@@ -50,7 +50,7 @@ describe('Collection', function() {
|
||||
|
||||
it('should respond to the built-in changed event on del', function(done) {
|
||||
dpd.todos.post({title: 'changed - create'}, function(item) {
|
||||
dpd.todos.on('changed', function() {
|
||||
dpd.todos.once('changed', function() {
|
||||
done();
|
||||
});
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ describe('User Collection', function() {
|
||||
});
|
||||
describe('dpd.users.on("changed", fn)', function() {
|
||||
it('should respond to the built-in changed event on post', function(done) {
|
||||
dpd.users.on('changed', function() {
|
||||
dpd.users.once('changed', function() {
|
||||
done();
|
||||
});
|
||||
|
||||
@@ -116,7 +116,7 @@ describe('User Collection', function() {
|
||||
|
||||
it('should respond to the built-in changed event on put', function(done) {
|
||||
dpd.users.post({username: 'foo2@bar.com', password: '123456'}, function(item) {
|
||||
dpd.users.on('changed', function() {
|
||||
dpd.users.once('changed', function() {
|
||||
done();
|
||||
});
|
||||
|
||||
@@ -126,7 +126,7 @@ describe('User Collection', function() {
|
||||
|
||||
it('should respond to the built-in changed event on del', function(done) {
|
||||
dpd.users.post({username: 'foo2@bar.com', password: '123456'}, function(item) {
|
||||
dpd.users.on('changed', function() {
|
||||
dpd.users.once('changed', function() {
|
||||
done();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user