-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
while loading feature should use error boundries #70
Comments
Because this might be useful outside of hyper-model, move the whole thing into hyper-component with necessary hooks for hyper-model, rather than the core implementation being in hyper-model. |
The component DSL changes have been implemented and a works like this:
You use the Here is an example using the Todo code: class App < HyperComponent
include Hyperstack::Router
include Hyperstack::Component::WhileLoading
def get_scope!(match)
@previous_scope = @scope
@scope = Todo.send(match.params[:scope])
end
SCOPES = %i[all active completed]
VALID_ROUTES = "/:scope(#{SCOPES.join('|')})"
render(SECTION, class: 'todo-app') do
if resources_loaded?
Header()
Switch() do
Route(App::VALID_ROUTES) { |match| Index(scope: get_scope!(match)) }
Route('/') { Redirect('/all') }
end
Footer()
elsif @previous_scope
Header()
Index(scope: @previous_scope)
Footer(:loading)
else
Header(:loading)
end
end
end When the component first renders Now Sometime later the data will be loaded, and so again this will trigger a rerender as We now once again render the first block, and this time all data is loaded so no fall back occurs. Also the value of Now if the user changes scopes, the cycle repeats. However this time when we execute the fallback While this may seem complicated, its fairly intuitive and requires very little additional code to give a great user experience, and the code can be added after the fact, and is limited to just the component that will handle the fall back. What the user sees on page load is a spinner while the data loads. There is no "flashing" or rerendering. Then once the data appears it immediately replaces the spinner. Then when the user clicks on a link to another route/scope, that link has a spinner, and the rest of the display stays as is, until the data is available, then immediately changes to the new scope. |
closed in 242d7a9 |
should also fix #67
The text was updated successfully, but these errors were encountered: