• Stars
    star
    273
  • Rank 150,780 (Top 3 %)
  • Language
    HTML
  • License
    Apache License 2.0
  • Created over 11 years ago
  • Updated about 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A JavaScript library that transitions between static HTML pages on navigation; no app server required.

TurboReact

TurboReact applies only the differences between two HTML pages when navigating with links rather than create a new document, which enables CSS transitions between pages without needing a server.

Installation & Usage

TurboReact is a plugin for Turbolinks, which means Turbolinks is required. Include both Turbolinks and TurboReact in the <head> of every document on your site.

Ruby on Rails

  1. Add the turbo_react-rails gem to your Gemfile:

    gem 'turbo_react-rails'
    
  2. Install the updated set of gems:

    $ bundle install
  3. Require the "turbo-react" library after "turbolinks" on every page, for example in "application.js" if it is on every page:

    //= require turbolinks
    //= require turbo-react

Plain HTML and Other Frameworks

  1. Get turbo-react via NPM or download the latest release from GitHub:

    $ yarn install turbo-react

    or

    $ curl https://raw.githubusercontent.com/ssorallen/turbo-react/v0.9.0/public/dist/turbo-react.min.js
  2. Include turbo-react in the <head> of each page of the site after Turbolinks:

    <!DOCTYPE html>
    <html>
      <head>
        ...
        <script src="path/to/turbolinks.js"></script>
        <script src="path/to/turbo-react.min.js"></script>
      </head>
      <body>
        ...
      </body>
    </html>

Opting out of Turbolinks & TurboReact

Add a data-no-turbolink attribute to any link that should load normally without being intercepted by Turbolinks and TurboReact. This feature is inherited from TurboReacts's use of Turbolinks.

<a href="/foo/bar.html" data-no-turbolink>
  Skip Turbolinks and TurboReact
</a>

Examples

Transitioning Background Colors

Navigating between page1 and page2 shows a skyblue background and a yellow background that changes at once. After putting TurboReact in the <head>, navigating between the pages will transition between the background colors because TurboReact will add and remove the class names rather than start a new document.

/* style.css */

body {
  height: 100%;
  margin: 0;
  transition: background-color 0.5s;
  width: 100%;
}

.bg-skyblue {
  background-color: skyblue;
}

.bg-yellow {
  background-color: yellow;
}
<!-- page1.html -->

<body class="bg-skyblue">
  <a href="page2.html">Page 2</a>
</body>
<!-- page2.html -->

<body class="bg-yellow">
  <a href="page1.html">Page 1</a>
</body>

How it Works

Demo: https://turbo-react.herokuapp.com/

"Re-request this page" is just a link to the current page. When you click it, Turbolinks intercepts the GET request and fetchs the full page via XHR.

The panel is rendered with a random panel- class on each request, and the progress bar gets a random widthX class.

With Turbolinks alone, the entire <body> would be replaced, and transitions would not happen. In this little demo though, React adds and removes classes and text, and the attribute changes are animated with CSS transitions. The DOM is otherwise left in tact.

The Code

TurboReact turns the <body> into a React element and re-renders it after Turbolinks intercepts link navigations via XMLHttpRequest: turbo-react.js

Running locally

  1. Clone this repo

     $ git clone https://github.com/ssorallen/turbo-react.git
    
  2. Install dependencies

     $ bundle install
     $ yarn install
    
  3. Run the server and watch JS changes

     $ bundle exec unicorn
     $ yarn watch
    
  4. Visit the app: http://localhost:9292

More Repositories

1

react-play

Render React components in the Play Framework with JDK8's JavaScript engine
JavaScript
214
star
2

jquery-scrollstop

A jQuery plugin that fires events when scrolling stops and starts.
HTML
156
star
3

finance

πŸ€‘ A free, fast, in-browser stock portfolio tracker
JavaScript
69
star
4

react-reddit-client

A Reddit client written with React.js
TypeScript
40
star
5

react-todos

Backbone's example TODO app with React Components for views
JavaScript
29
star
6

redux-persist-webextension-storage

A WebExtension Storage storage engine for redux-persist
JavaScript
29
star
7

hackernews-react

A Hacker News API Client in React + Firebase
JavaScript
19
star
8

googly-eyed-mona-lisa

Mona Lisa's eyes follow your face via your computer's camera
HTML
7
star
9

turbo_react-rails

TurboReact for the Rails Asset Pipeline.
Ruby
6
star
10

dotfiles

Ross Allen's dotfiles and preferred settings
Shell
4
star
11

blob-feature-check

Small feature check for "blob:" URL support.
JavaScript
4
star
12

blacklotusproject

Parts of Black Lotus Project that might be useful for other people interested in some Magic development.
JavaScript
3
star
13

cat-face

A custom element for delivering happiness via Cat Face episodes.
HTML
2
star
14

vanillajs-keyboard

A keyboard rendered with JS and no 3rd-party libraries
JavaScript
2
star
15

polymer-reddit-client

A simple Reddit client written with Polymer.js.
HTML
1
star
16

camtime

Take and review pictures all from inside your mobile web browser
JavaScript
1
star
17

gifs-r-us

All the GIFs you'll ever need are at Gifs-R-Us
TypeScript
1
star
18

airdryer

A Chrome Extension that makes airbrake.io a little more friendly
JavaScript
1
star