forked from Morriz/backbone-redis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
d
113 lines (113 loc) · 3.86 KB
/
d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
[1mdiff --git a/browser/backbone.redis.js b/browser/backbone.redis.js[m
[1mindex 710e61b..501d57d 100644[m
[1m--- a/browser/backbone.redis.js[m
[1m+++ b/browser/backbone.redis.js[m
[36m@@ -17,7 +17,7 @@[m
var socket;[m
[m
// Default socket event listener[m
[31m- var listener = 'backbone';[m
[32m+[m[32m var listener = 'message';[m
[m
// Storage container for subscribed models, allowing the returning method[m
// calls from the server know where and how to find the model in question[m
[1mdiff --git a/examples/server.js b/examples/server.js[m
[1mindex 01b56be..c2eac0e 100644[m
[1m--- a/examples/server.js[m
[1m+++ b/examples/server.js[m
[36m@@ -93,6 +93,67 @@[m [mmodel = support[m
next(sock, data, cb);[m
})[m
.model('todo', model);[m
[32m+[m[41m [m
[32m+[m
[32m+[m[32mvar Todo = Backbone.Model.extend({[m
[32m+[m
[32m+[m[32m // Server communication settings[m
[32m+[m[32m url : 'todos',[m
[32m+[m[32m type : 'todo',[m
[32m+[m[32m sync : _.sync,[m
[32m+[m
[32m+[m[32m // Default attributes for the todo.[m
[32m+[m[32m defaults: {[m
[32m+[m[32m content: "empty todo...",[m
[32m+[m[32m done: false,[m
[32m+[m[32m },[m
[32m+[m
[32m+[m[32m // Ensure that each todo created has `content`.[m
[32m+[m[32m initialize: function() {[m
[32m+[m[32m if (!this.get("content")) {[m
[32m+[m[32m this.set({"content": this.defaults.content});[m
[32m+[m[32m }[m
[32m+[m[32m },[m
[32m+[m
[32m+[m[32m // Toggle the `done` state of this todo item.[m
[32m+[m[32m toggle: function() {[m
[32m+[m[32m this.save({done: !this.get("done")});[m
[32m+[m[32m },[m
[32m+[m
[32m+[m[32m // Remove this Todo from *localStorage* and delete its view.[m
[32m+[m[32m clear: function() {[m
[32m+[m[32m this.destroy();[m
[32m+[m[32m }[m
[32m+[m
[32m+[m[32m});[m
[32m+[m
[32m+[m[32mvar TodosList = Backbone.Collection.extend({[m
[32m+[m[32m model: Todo,[m
[32m+[m[32m url : 'todos',[m
[32m+[m[32m type : 'todo',[m
[32m+[m[32m sync : _.sync[m
[32m+[m[32m});[m
[32m+[m
[32m+[m[32mvar Todos = new TodoList;[m
[32m+[m
[32m+[m[32mTodos.bind('add', function((todo) {[m
[32m+[m[32m console.log('todo added', todo);[m
[32m+[m[32m});[m
[32m+[m
[32m+[m[32mTodos.bind('reset', function(todos) {[m
[32m+[m[32m console.log('todo reset', todos);[m
[32m+[m[32m});[m
[32m+[m
[32m+[m[32mTodos.subscribe({}, function() {[m
[32m+[m[32m console.log('todos subscribed');[m
[32m+[m[41m [m
[32m+[m[32m Todos.fetch();[m
[32m+[m[41m [m
[32m+[m[32m Todos.create({[m
[32m+[m[32m content: 'server',[m
[32m+[m[32m done : false[m
[32m+[m[32m });[m
[32m+[m[32m});[m
[m
[m
server.listen(8080);[m
[1mdiff --git a/lib/backbone-redis.js b/lib/backbone-redis.js[m
[1mindex c1189cc..cfe0436 100644[m
[1m--- a/lib/backbone-redis.js[m
[1m+++ b/lib/backbone-redis.js[m
[36m@@ -10,7 +10,7 @@[m [mvar pub,[m
db;[m
[m
// Default socket event listener[m
[31m-var listener = 'backbone';[m
[32m+[m[32mvar listener = 'message';[m
[m
// Socket.io connection reference[m
var conn;[m
[36m@@ -40,6 +40,12 @@[m [mif (typeof exports !== 'undefined') {[m
var hooks = require('hooks');[m
}[m
[m
[32m+[m[32mfunction Message(opt) {[m
[32m+[m[32m this.model = opt.model;[m
[32m+[m[32m this.options = opt.options;[m
[32m+[m[32m this.options.type && (this.type = this.options.type);[m
[32m+[m[32m}[m
[32m+[m
// Error and debug handlers[m
//-------------------------[m
[m
warning: CRLF will be replaced by LF in examples/server.js.
The file will have its original line endings in your working directory.