batman-rails-flo 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a80dbb083d250de25b133e8977f407db24fb1797
4
- data.tar.gz: 5889c813d18a6590a49d2fda403015e1ef068e48
3
+ metadata.gz: 22d46aeb72056e2b0ce7078c5c21e1400f71f502
4
+ data.tar.gz: f3640116508c0e74466a879f9b7ae8a10a44c2c6
5
5
  SHA512:
6
- metadata.gz: e828a073f8ee7272ae1d55debe1ad39e89626311786d82e9bc50a10c667358d936d48e160593656f4d1d573f7ea9f69f7bc830a99a7119205a41844c376d50ca
7
- data.tar.gz: f3da4a8c02e8687175a6f5588bf530ee8c55c6841cd6a467783b7d1914d1cdabc7f13ef8fb0beb40fd28527ee55b1fa5e30de6eb32490896a7c65500f0008f63
6
+ metadata.gz: 23a60b364fa0f7c35660b40c1384d43bd64d1849ff1181ffe915f11422b2928634f5e028b4c87b0da2e908e7fbf3bc08765dbb095519c49df7100df0b8617abe
7
+ data.tar.gz: 8bd917956d12cc23b9ab243a3d8fd9386ef5629073e06170d5996eced5ce63a710abef58b84e528a7bc16a2ece4db0fc7cf06ff9f2d802f33faddeccaa28364f
@@ -1,3 +1,3 @@
1
1
  module BatmanRailsFlo
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,129 +1,2 @@
1
-
2
- # Force batman.js to look up & calculate accessors again.
3
- Batman.Object::liveReload = (newConstructor) ->
4
- throw "You must pass a constructor to liveReload" unless newConstructor?
5
- @_batman._allAncestors = false # force recalculation
6
- @__proto__ = newConstructor.prototype
7
- @constructor = newConstructor
8
- Batman.initializeObject(@)
9
- @refreshProperties()
10
-
11
-
12
- Batman.Object::refreshProperties = ->
13
- @_batman.properties.forEach (name, property) ->
14
- if property instanceof Batman.Keypath
15
- property.terminalProperty().refresh()
16
- property.refresh()
17
-
18
- ###
19
- This will force reload of class accessors that are rendered in views.
20
- ###
21
-
22
- Batman.App.liveReloadClass = (className) ->
23
- re = new RegExp(className)
24
- @_batman.properties.forEach (name, property) ->
25
- if name.match(re)
26
- property.refresh()
27
-
28
- ###
29
- For app classes, `.liveReload` has to:
30
-
31
- - Identify existing instances of the class
32
- - Load the new class
33
- - Live-reload existing instances with the new class
34
- - Attach those existing instances to the new constructor (so they'll be found again next time)
35
- ###
36
-
37
- Batman.Model.liveReload = (className, newCode) ->
38
- existing = @get('loaded')
39
- eval(newCode)
40
- newClass = Batman.currentApp[className]
41
- existing.forEach (record) ->
42
- record.liveReload(newClass)
43
- newClass.set('loaded', existing)
44
-
45
- Batman.Controller.liveReload = (className, newCode) ->
46
- instance = @get('_sharedController')
47
- eval(newCode)
48
- return unless instance # it's possible it hasn't been instantiated yet
49
- newClass = Batman.currentApp[className]
50
- instance.liveReload(newClass)
51
- newClass.set("_sharedController", instance)
52
- instance.get('currentView')?.refreshProperties()
53
- route = App.get('currentRoute')
54
- params = App.get('currentParams').toObject()
55
- route.dispatch(params)
56
-
57
- Batman.View.refreshProperties = ->
58
- Batman.Object::refreshProperties.call(@)
59
- @subviews?.forEach (sv) ->
60
- sv.refreshProperties(sv)
61
-
62
- Batman.View.liveReload = (className, newCode) ->
63
- currentViews = @_currentViews
64
- eval(newCode)
65
- newClass = Batman.currentApp[className]
66
- currentViews?.forEach (view) ->
67
- view.liveReload(newClass)
68
- newClass._currentViews = currentViews
69
-
70
- # Track view instances so that they can be reloaded
71
- Batman.View::on 'viewDidAppear', ->
72
- @constructor._currentViews ||= new Batman.SimpleSet
73
- @constructor._currentViews.add(@)
74
-
75
- Batman.View::on 'viewWillDisappearAppear', ->
76
- @constructor._currentViews.remove(@)
77
-
78
- # Out of the box, HTMLStore's default accessor is _final_,
79
- # meaning it can't change after the first `set`.
80
- # Let's undo that:
81
- storeAccessor = Batman.HTMLStore::_batman.getFirst('defaultAccessor')
82
- storeAccessor.final = false
83
-
84
- # And define an unset operation:
85
- storeAccessor.unset = (path) ->
86
- if !path.charAt(0) is "/"
87
- path = "/#{path}"
88
- @_requestedPaths.remove(path)
89
- @_htmlContents[path] = undefined
90
-
91
- # Climbs the view tree, looking for one that has a source
92
- Batman.View::superviewWithSource = ->
93
- if @get('source')?
94
- return @
95
- else
96
- return @?superview.superviewWithSource()
97
-
98
- # Refresh HTML by finding the next view with a source
99
- # and refreshing subviews
100
- Batman.View::refreshHTML = (stack=[])->
101
- @sourceView ?= @superviewWithSource()
102
- if @sourceView?
103
- @_refreshSourceView(stack)
104
- if @subviews?.length
105
- @_refreshSubviews()
106
-
107
- Batman.View::_refreshSourceView = (stack) ->
108
- @sourceView.html = undefined
109
- path = @sourceView.get('source')
110
- if path.charAt(0) isnt "/"
111
- path = "/#{path}"
112
- return if path in stack
113
- stack.push(path)
114
- Batman.View.store.unset(path)
115
- Batman.View.store.observeOnce path, (nv, ov) =>
116
- @sourceView.set('html', nv)
117
- @sourceView.loadView()
118
- @sourceView.initializeBindings()
119
-
120
- Batman.View::_refreshSubviews = ->
121
- @subviews?.forEach (sv) ->
122
- if sv.get('source')?
123
- sv.refreshHTML()
124
- if sv.subviews?.length
125
- sv._refreshSubviews()
126
-
127
- Batman.View.liveReloadHTML = ->
128
- # Refresh all HTML, going down from `layout`
129
- Batman.currentApp.get('layout').refreshHTML([])
1
+ #= require ./reload_event_handler
2
+ #= require ./reload_implementations
@@ -1,4 +1,3 @@
1
- #= require ./live_reload
2
1
  handleLiveReloadEvent = (ev) ->
3
2
  try
4
3
  code = ev.data.contents
@@ -0,0 +1,129 @@
1
+
2
+ # Force batman.js to look up & calculate accessors again.
3
+ Batman.Object::liveReload = (newConstructor) ->
4
+ throw "You must pass a constructor to liveReload" unless newConstructor?
5
+ @_batman._allAncestors = false # force recalculation
6
+ @__proto__ = newConstructor.prototype
7
+ @constructor = newConstructor
8
+ Batman.initializeObject(@)
9
+ @refreshProperties()
10
+
11
+
12
+ Batman.Object::refreshProperties = ->
13
+ @_batman.properties.forEach (name, property) ->
14
+ if property instanceof Batman.Keypath
15
+ property.terminalProperty().refresh()
16
+ property.refresh()
17
+
18
+ ###
19
+ This will force reload of class accessors that are rendered in views.
20
+ ###
21
+
22
+ Batman.App.liveReloadClass = (className) ->
23
+ re = new RegExp(className)
24
+ @_batman.properties.forEach (name, property) ->
25
+ if name.match(re)
26
+ property.refresh()
27
+
28
+ ###
29
+ For app classes, `.liveReload` has to:
30
+
31
+ - Identify existing instances of the class
32
+ - Load the new class
33
+ - Live-reload existing instances with the new class
34
+ - Attach those existing instances to the new constructor (so they'll be found again next time)
35
+ ###
36
+
37
+ Batman.Model.liveReload = (className, newCode) ->
38
+ existing = @get('loaded')
39
+ eval(newCode)
40
+ newClass = Batman.currentApp[className]
41
+ existing.forEach (record) ->
42
+ record.liveReload(newClass)
43
+ newClass.set('loaded', existing)
44
+
45
+ Batman.Controller.liveReload = (className, newCode) ->
46
+ instance = @get('_sharedController')
47
+ eval(newCode)
48
+ return unless instance # it's possible it hasn't been instantiated yet
49
+ newClass = Batman.currentApp[className]
50
+ instance.liveReload(newClass)
51
+ newClass.set("_sharedController", instance)
52
+ instance.get('currentView')?.refreshProperties()
53
+ route = App.get('currentRoute')
54
+ params = App.get('currentParams').toObject()
55
+ route.dispatch(params)
56
+
57
+ Batman.View.refreshProperties = ->
58
+ Batman.Object::refreshProperties.call(@)
59
+ @subviews?.forEach (sv) ->
60
+ sv.refreshProperties(sv)
61
+
62
+ Batman.View.liveReload = (className, newCode) ->
63
+ currentViews = @_currentViews
64
+ eval(newCode)
65
+ newClass = Batman.currentApp[className]
66
+ currentViews?.forEach (view) ->
67
+ view.liveReload(newClass)
68
+ newClass._currentViews = currentViews
69
+
70
+ # Track view instances so that they can be reloaded
71
+ Batman.View::on 'viewDidAppear', ->
72
+ @constructor._currentViews ||= new Batman.SimpleSet
73
+ @constructor._currentViews.add(@)
74
+
75
+ Batman.View::on 'viewWillDisappearAppear', ->
76
+ @constructor._currentViews.remove(@)
77
+
78
+ # Out of the box, HTMLStore's default accessor is _final_,
79
+ # meaning it can't change after the first `set`.
80
+ # Let's undo that:
81
+ storeAccessor = Batman.HTMLStore::_batman.getFirst('defaultAccessor')
82
+ storeAccessor.final = false
83
+
84
+ # And define an unset operation:
85
+ storeAccessor.unset = (path) ->
86
+ if !path.charAt(0) is "/"
87
+ path = "/#{path}"
88
+ @_requestedPaths.remove(path)
89
+ @_htmlContents[path] = undefined
90
+
91
+ # Climbs the view tree, looking for one that has a source
92
+ Batman.View::superviewWithSource = ->
93
+ if @get('source')?
94
+ return @
95
+ else
96
+ return @?superview.superviewWithSource()
97
+
98
+ # Refresh HTML by finding the next view with a source
99
+ # and refreshing subviews
100
+ Batman.View::refreshHTML = (stack=[])->
101
+ @sourceView ?= @superviewWithSource()
102
+ if @sourceView?
103
+ @_refreshSourceView(stack)
104
+ if @subviews?.length
105
+ @_refreshSubviews()
106
+
107
+ Batman.View::_refreshSourceView = (stack) ->
108
+ @sourceView.html = undefined
109
+ path = @sourceView.get('source')
110
+ if path.charAt(0) isnt "/"
111
+ path = "/#{path}"
112
+ return if path in stack
113
+ stack.push(path)
114
+ Batman.View.store.unset(path)
115
+ Batman.View.store.observeOnce path, (nv, ov) =>
116
+ @sourceView.set('html', nv)
117
+ @sourceView.loadView()
118
+ @sourceView.initializeBindings()
119
+
120
+ Batman.View::_refreshSubviews = ->
121
+ @subviews?.forEach (sv) ->
122
+ if sv.get('source')?
123
+ sv.refreshHTML()
124
+ if sv.subviews?.length
125
+ sv._refreshSubviews()
126
+
127
+ Batman.View.liveReloadHTML = ->
128
+ # Refresh all HTML, going down from `layout`
129
+ Batman.currentApp.get('layout').refreshHTML([])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: batman-rails-flo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Mosolgo
@@ -205,6 +205,7 @@ files:
205
205
  - vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/test/server/flo_test.js
206
206
  - vendor/assets/javascripts/batman_rails_flo/package.json
207
207
  - vendor/assets/javascripts/batman_rails_flo/reload_event_handler.js.coffee
208
+ - vendor/assets/javascripts/batman_rails_flo/reload_implementations.js.coffee
208
209
  homepage: https://github.com/rmosolgo/batman-rails-flo
209
210
  licenses:
210
211
  - MIT