revelry_core 0.1.8.2 → 0.1.8.3
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa4ab2470c5392562e8f5fa32849012628e07f0b
|
4
|
+
data.tar.gz: b6d3f57b20aaaa6c9dced986aeec290e6d982b13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5d4735dc6bb8bb5a06e13d9a121b96b2e59c850dd27668e21bd3c01bf9a717c50830b4345a4cbe44d78604cf0aee2ecda74331a7b974b9d2b419053e784d19a
|
7
|
+
data.tar.gz: 5f7e4897b904c5a4d2ad127f882eb1f53677471a26d81767abddf2191824409961fa3867e182cbfbbc53b70bef48cd350e9c3516bbae9d202c686aa4db69af35
|
@@ -2,6 +2,8 @@
|
|
2
2
|
<%# Ensure routes are loaded during precompile. %>
|
3
3
|
<% Rails.application.reload_routes! %>
|
4
4
|
|
5
|
+
CSSTransitionGroup = React.addons.CSSTransitionGroup
|
6
|
+
|
5
7
|
Rev.registerComponent 'Router',
|
6
8
|
### CLASS METHODS ###
|
7
9
|
|
@@ -43,12 +45,31 @@ Rev.registerComponent 'Router',
|
|
43
45
|
|
44
46
|
mixins: [Backbone.Events]
|
45
47
|
|
48
|
+
getDefaultProps: ->
|
49
|
+
loadingScreenDelay: 800
|
50
|
+
|
46
51
|
getInitialState: ->
|
47
52
|
bbRouter: new Backbone.Router(Rev.Components.Router.routerConfig())
|
48
53
|
# Seed the path and options (which we pass down to child components) from
|
49
54
|
# the initial props we received. Updates will come from the AJAX prop fetch.
|
50
55
|
path: @props.path
|
51
56
|
options: @props.options
|
57
|
+
isLoading: false
|
58
|
+
|
59
|
+
# Loading state is just used to show the loading screen or not.
|
60
|
+
# Best practice is to introduce a delay before showing a loading screen.
|
61
|
+
# Below a certain time threshold, users actually prefer to not see that crap.
|
62
|
+
# Configure the delay with @props.loadingScreenDelay
|
63
|
+
setLoading: (isLoading) ->
|
64
|
+
if isLoading
|
65
|
+
unless @_loadingTimeoutHandle?
|
66
|
+
fn = () => @setState isLoading: true
|
67
|
+
@_loadingTimeoutHandle = setTimeout fn, @props.loadingScreenDelay
|
68
|
+
else
|
69
|
+
if @_loadingTimeoutHandle?
|
70
|
+
clearTimeout @_loadingTimeoutHandle
|
71
|
+
delete @_loadingTimeoutHandle
|
72
|
+
@setState isLoading: false
|
52
73
|
|
53
74
|
componentDidMount: ->
|
54
75
|
# Start history to pay attention to pushState and hashChange events
|
@@ -68,7 +89,7 @@ Rev.registerComponent 'Router',
|
|
68
89
|
"/#{baseUrl}?#{if query? and query.length then '&' else ''}#{encodeURIComponent '__props'}"
|
69
90
|
|
70
91
|
# Fall back to full page navigation request
|
71
|
-
|
92
|
+
doFailureFallback: ->
|
72
93
|
window.location = @locationURL()
|
73
94
|
|
74
95
|
# Make a handler for successful props fetching of a given templatePath
|
@@ -77,27 +98,57 @@ Rev.registerComponent 'Router',
|
|
77
98
|
return (data, textStatus, xhr)=>
|
78
99
|
try
|
79
100
|
@setState path: templatePath, options: JSON.parse(data)
|
101
|
+
@setLoading false
|
80
102
|
window.scrollTo 0, 0
|
81
103
|
catch err
|
82
|
-
@
|
104
|
+
@doFailureFallback()
|
83
105
|
|
84
106
|
routeChangeHandler: (templatePath, params)->
|
107
|
+
@setLoading true
|
85
108
|
# Request the same props from the server that we would get for a server-side
|
86
109
|
# render. If we get them back successfully, swap the page. If we fail, fall
|
87
110
|
# back to server side render.
|
88
|
-
|
111
|
+
@_xhr.abort() if @_xhr?
|
112
|
+
@_xhr = Backbone.ajax
|
89
113
|
url: @locationURL()
|
90
114
|
beforeSend: (xhr) ->
|
91
115
|
xhr.setRequestHeader "Content-Type", "text/reactprops"
|
92
116
|
xhr.setRequestHeader "Accept", "text/reactprops"
|
93
117
|
success: @makePropsFetchSuccessHandler(templatePath)
|
94
|
-
error: @
|
118
|
+
error: @onRouteChangeError
|
95
119
|
true
|
96
120
|
|
97
|
-
|
98
|
-
|
121
|
+
onRouteChangeError: (xhr) ->
|
122
|
+
# Aborts aren't really errors.
|
123
|
+
@doFailureFallback unless xhr.statusText == "abort"
|
124
|
+
|
125
|
+
getKey: (isInCSSTransitionGroup) ->
|
126
|
+
# We never need to compute any keys at all unless we're not using CSSTransitionGroup.
|
127
|
+
if isInCSSTransitionGroup
|
128
|
+
# We can use a generic key for the loading screen.
|
129
|
+
if @state.isLoading
|
130
|
+
'GENERIC_ROUTER_KEY'
|
131
|
+
# Actual screens need a unique computed key to tell the CSSTransitionGroup something changed.
|
132
|
+
else
|
133
|
+
JSON.stringify path: @state.path, options: @state.options
|
134
|
+
|
135
|
+
# Show a loading screen if we're loading. Show the content if we're done.
|
136
|
+
renderInner: (isInCSSTransitionGroup = false) ->
|
137
|
+
<div className="RevRouter" key={@getKey isInCSSTransitionGroup}>
|
99
138
|
{
|
100
|
-
|
101
|
-
|
139
|
+
if @state.isLoading
|
140
|
+
@props.loadingScreen or <h1 className="RevRouter-loadingScreen">Loading...</h1>
|
141
|
+
else
|
142
|
+
React.Children.map @props.children, (child)=>
|
143
|
+
React.addons.cloneWithProps child, { path: @state.path, options: @state.options }
|
102
144
|
}
|
103
145
|
</div>
|
146
|
+
|
147
|
+
render: ->
|
148
|
+
# If you give it a transitionName, it will wrap everything in a CSSTransitionGroup
|
149
|
+
# All props are passed down, so Router can take any props that a CSSTransitionGroup can.
|
150
|
+
if @props.transitionName
|
151
|
+
<CSSTransitionGroup {...@props}>{@renderInner(true)}</CSSTransitionGroup>
|
152
|
+
# No transitionName? Don't do anything fancy.
|
153
|
+
else
|
154
|
+
@renderInner()
|
data/lib/revelry_core/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: revelry_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.8.
|
4
|
+
version: 0.1.8.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Revelry Labs, LLC
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|