revelry_core 0.1.8.2 → 0.1.8.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: 0ff30f1fa34db5dc199df1033b972481671001d2
4
- data.tar.gz: e99f24e33a966ff5f0b68572d17fc2a64dd51bff
3
+ metadata.gz: fa4ab2470c5392562e8f5fa32849012628e07f0b
4
+ data.tar.gz: b6d3f57b20aaaa6c9dced986aeec290e6d982b13
5
5
  SHA512:
6
- metadata.gz: f79afb934c3b231a445d7ba262ee314c07fd804263c68cf21100def07770ccda531dc7fbf2b43c4bd88ddcc344446e931db40275ab46f6cc1e54233da9a94ccd
7
- data.tar.gz: 914edc2c42526840d7f6ca488f5080c46e371ba0121d4a00575fa8e986f951480a048e4b58af3430276f4844f17d08cd9b188679d727f92ff7ec7c495b77a9a9
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
- onPropsFetchFailure: ->
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
- @onPropsFetchFailure()
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
- Backbone.ajax
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: @onPropsFetchFailure
118
+ error: @onRouteChangeError
95
119
  true
96
120
 
97
- render: ->
98
- <div className="RevRouter">
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
- React.Children.map @props.children, (child)=>
101
- React.addons.cloneWithProps child, { path: @state.path, options: @state.options }
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()
@@ -1,5 +1,5 @@
1
1
  module Revelry
2
2
  module Core
3
- VERSION = "0.1.8.2"
3
+ VERSION = "0.1.8.3"
4
4
  end
5
5
  end
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.2
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-26 00:00:00.000000000 Z
11
+ date: 2015-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails