seapig-rails 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23f1145dd4d6fb56d90fa41f44e2d652440f0d16
|
4
|
+
data.tar.gz: aefcf64b92b67673f4720c88078ef71f146cc27e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af39161ee44bff9348c655e384c6f01facd81a596efdbd5a0f5863a2fd22423a9cf265ef2316657a08fd4521755550b128137fd27213187eb000628e4bdc38f2
|
7
|
+
data.tar.gz: 07f2aeba1327c29252b019ec3919c2afb1cce8031803dfa87d93a78279f748643266380b68ecebfee7dc325efc503b854e567a0b53124a4585e703776dea7ec5
|
@@ -91,8 +91,9 @@ class SeapigObject
|
|
91
91
|
changed: () ->
|
92
92
|
old_version = @version
|
93
93
|
@version += 1
|
94
|
-
|
94
|
+
old_object = @shadow
|
95
95
|
@shadow = JSON.parse(JSON.stringify(@object))
|
96
|
+
@upload(old_version, old_object)
|
96
97
|
|
97
98
|
|
98
99
|
upload: (old_version, old_object)->
|
@@ -101,7 +102,7 @@ class SeapigObject
|
|
101
102
|
action: 'object-patch'
|
102
103
|
old_version: old_version
|
103
104
|
new_version: @version
|
104
|
-
patch: jsonpatch.compare(old_object, @
|
105
|
+
patch: jsonpatch.compare(old_object, @shadow)
|
105
106
|
}
|
106
107
|
@server.socket.send(JSON.stringify(message)) if @server.connected
|
107
108
|
|
@@ -11,14 +11,16 @@ class @SeapigRouter
|
|
11
11
|
@session_data = @seapig_server.master('web-session-data-'+@session_id)
|
12
12
|
@session_data.object.states = [ @state ]
|
13
13
|
@session_data.sequence = 1
|
14
|
+
@session_data.bases = {}
|
14
15
|
@session_data.changed()
|
15
16
|
|
16
17
|
@session_data_saved = @seapig_server.slave('web-session-saved-'+@session_id)
|
17
18
|
@session_data_saved.onchange = ()=>
|
18
19
|
while @session_data.object.states[0]? and @session_data.object.states[0].id < @session_data_saved.object.max_state_id
|
19
20
|
@session_data.object.states.shift()
|
21
|
+
console.log('Session saved, updating url:',@current_url()) if @debug
|
20
22
|
@replacing_state = true
|
21
|
-
window.history.replaceState(@state,null,@current_url())
|
23
|
+
window.history.replaceState(@state,null,@current_url()) if @state_valid
|
22
24
|
@replacing_state = false
|
23
25
|
|
24
26
|
|
@@ -26,8 +28,8 @@ class @SeapigRouter
|
|
26
28
|
@state_valid = false
|
27
29
|
|
28
30
|
$(document).on('click','a', (event) =>
|
29
|
-
console.log('ROUTER: A-element clicked, changing location to:', event.target.href) if @debug
|
30
|
-
return true if not event.target.href[0] == '?'
|
31
|
+
console.log('ROUTER: A-element clicked, changing location to:', $(event.target).attr('href')) if @debug
|
32
|
+
return true if not ($(event.target).attr('href')[0] == '?')
|
31
33
|
window.history.pushState(null,null,event.target.href)
|
32
34
|
@location_changed()
|
33
35
|
false
|
@@ -44,44 +46,52 @@ class @SeapigRouter
|
|
44
46
|
console.log('ROUTER: Location changed to: pathname:', window.location.pathname, ' search:', window.location.search) if @debug
|
45
47
|
|
46
48
|
spl = window.location.pathname.split('/')
|
47
|
-
|
48
|
-
|
49
|
-
|
49
|
+
spl.shift()
|
50
|
+
if spl.shift() == 'a'
|
51
|
+
path_session_id = spl.shift()
|
52
|
+
path_state_id = spl.shift()
|
50
53
|
else
|
51
54
|
path_session_id = @session_id
|
52
55
|
path_state_id = 0
|
56
|
+
spl = []
|
53
57
|
|
54
|
-
|
58
|
+
diff = []
|
59
|
+
while spl.length > 0
|
60
|
+
diff.push([spl.shift(),spl.shift()])
|
55
61
|
if window.location.search.length > 0
|
56
62
|
for pair in window.location.search.split('?')[1].split('&')
|
57
|
-
|
58
|
-
|
63
|
+
diff.push(pair.split('=',2))
|
64
|
+
console.log('Parsed location: session_id:',path_session_id,' diff:', diff) if @debug
|
59
65
|
|
60
66
|
if path_session_id == @session_id
|
61
|
-
@state_change(
|
67
|
+
@state_change(diff)
|
62
68
|
else
|
63
69
|
if @remote_state?
|
64
|
-
@state_change_to_remote(
|
70
|
+
@state_change_to_remote(diff)
|
65
71
|
else
|
66
72
|
@state_valid = false
|
67
73
|
@remote_state = @seapig_server.slave('web-session-state-'+path_session_id+':'+path_state_id)
|
68
|
-
@remote_state.onchange = ()=> @state_change_to_remote(
|
74
|
+
@remote_state.onchange = ()=> @state_change_to_remote(diff)
|
69
75
|
|
70
76
|
|
71
|
-
state_change_to_remote: (
|
77
|
+
state_change_to_remote: (diff) ->
|
72
78
|
@state = _.clone(@remote_state.object)
|
73
|
-
if
|
74
|
-
@state_change(
|
79
|
+
if diff.length > 0
|
80
|
+
@state_change(diff)
|
75
81
|
else
|
82
|
+
#@session_data.object.states.push(@state)
|
76
83
|
@state_valid = true
|
77
84
|
@state_changed()
|
78
85
|
|
79
86
|
|
80
|
-
state_change: (
|
81
|
-
|
87
|
+
state_change: (diff) ->
|
88
|
+
base_state = @state
|
89
|
+
@state = @state_diff_apply(_.clone(@state), diff)
|
90
|
+
@state.diff = diff
|
82
91
|
@statefilter(@state) if @statefilter?
|
83
92
|
@state.session_id = @session_id
|
84
93
|
@state.id = @session_data.sequence++
|
94
|
+
@session_data.bases[@state.id] = base_state
|
85
95
|
@session_data.object.states.push(@state)
|
86
96
|
@session_data.changed()
|
87
97
|
if @remote_state?
|
@@ -91,8 +101,34 @@ class @SeapigRouter
|
|
91
101
|
@state_changed()
|
92
102
|
|
93
103
|
|
104
|
+
state_diff_apply: (state, diff)->
|
105
|
+
for entry in diff
|
106
|
+
if entry[0][0] == '-'
|
107
|
+
delete state[entry[0][1..-1]]
|
108
|
+
else
|
109
|
+
state[entry[0]] = entry[1]
|
110
|
+
state
|
111
|
+
|
112
|
+
|
113
|
+
state_diff_to_path: (diff)->
|
114
|
+
('/'+entry[0]+'/'+entry[1] for entry in diff).join("") or ""
|
115
|
+
|
116
|
+
|
94
117
|
current_url: ()->
|
95
|
-
|
118
|
+
base_state = @state
|
119
|
+
chain = []
|
120
|
+
while @session_data.bases[base_state.id] and (@session_id == base_state.session_id) and ((@session_data_saved.object.max_state_id or 0 ) < base_state.id)
|
121
|
+
chain.unshift(base_state)
|
122
|
+
base_state = @session_data.bases[base_state.id]
|
123
|
+
console.log('Last shareable url:', base_state, chain) if @debug
|
124
|
+
path_overlay = ""
|
125
|
+
for state in chain
|
126
|
+
console.log('-',state) if @debug
|
127
|
+
path_overlay += @state_diff_to_path(state.diff)
|
128
|
+
|
129
|
+
console.log('Calculated url:','/a/'+base_state.session_id+'/'+base_state.id+path_overlay) if @debug
|
130
|
+
'/a/'+base_state.session_id+'/'+base_state.id+path_overlay
|
131
|
+
|
96
132
|
|
97
133
|
state_changed: () ->
|
98
134
|
|
data/lib/seapig/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seapig-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yunta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|