Coder Social home page Coder Social logo

meteor-routecore's Introduction

RouteCore

RouteCore is a Meteor plugin which builds upon a series of other projects, including page.js, connect-route, fast-render, and react. RouteCore extends Meteor, adding server-side rendering using the react library, and client/server routing.

With RouteCore, you share your rendering code across the client and the server, meaning that you can have fast page load times, and your pages are avaliable to search engines for indexing.

Installation

RouteCore is on atmosphere.

To install on Meteor 0.9 or later:

meteor add mystor:routecore

Previous versions of Meteor can install it using meteorite.

mrt add routecore

Examples

The Page Context

On the client, values such as the session are stored in the global scope, as the entire scope for the code is one user. However, on the server we cannot use the global scope. Multiple clients can be interacting with the same server, and they need to have distinct sessions, userIds, etc. during their page's server-side rendering.

However, we want to enable people to use the same code that they would use on the client on the server, thus, we have the the Page Context.

On the server, these global state values, such as Session, Meteor.user, etc. are stored within the Page Context. There is a unique page context for every request to the server. For API consistency, this context is also avaliable on the client, however it simply defers to built-in Meteor calls.

In a function route, the page context is bound to this. If you are elsewhere in the route, you can get the page context by calling RouteCore.context().

NOTE RouteCore does not send the session values which are generated on the server to the client. When the client renders code for the first time, it is expected that it will generate identical session values.

NOTE On the server, the current fiber is used to store the page context. If code creates a new fiber or runs code in a new fiber, it will not have access to the page context.

Methods

The page context has the following methods:

ctx.subscribe(args...) // Meteor.subscribe()
ctx.user()             // Meteor.user()
ctx.userId()           // Meteor.userId()
ctx.loggingIn()        // Meteor.loggingIn()

ctx.set(k, v)          // Session.set()
ctx.get(k)             // Session.get()
ctx.setDefault(k, v)   // Session.setDefault()
ctx.equals(k1, k2)     // Session.equals()

ctx.redirect()         // Redirect to a different URL

Global Binding

It is possible to get RouteCore to bind these context values to the global scope. As this could potentially have negative side-effects, it is not this way by default. If you call RouteCore.bindGlobals(), RouteCore will define the following global functions on the server:

Meteor.subscribe();
Meteor.user();
Meteor.userId();
Meteor.loggingIn();

Session.get(k);
Session.set(k, v);
Session.setDefault(k, v);
Session.equals(k1, k2);

These functions only work on the server when in a RouteCore route, and will not work in other parts of Meteor code.

NOTE It is completely safe to call RouteCore.bindGlobals() on the client. It is currently a no-op.

Usage

JSX

RouteCore contains the jsx transformer from react-tools, and will transform any .jsx files with it. The jsx transformer will not perform any transformations unless the comment /** @jsx React.DOM */ is placed at the top of the file.

Defining Routes

Routes are defined within a RouteCore.map block. To define a route, call this.route.

this.route takes 2 arguments:

  1. A path spec. RouteCore uses page.js and connect-route for routing, and they use express-style path specs. (example: /static/:required/:optional?)

  2. One of the following:

    1. A function: The return value of this function should be an initialized react component which will be rendered by React. This function will be passed one object (the request context - has url and params properties). The page context is bound to this within the function.
    2. A React component: The params passed to the component will be the path segments from the URL.

this.route() returns a function, which when called returns the path for the route.

Example

/** @jsx React.DOM */

HomePage = React.createClass({ ... });
FriendsPage = React.createClass({ ... });

RouteCore.map(function() {
  var home = this.route('/', HomePage);
  var friends = this.route('/:user/friends', FriendsPage);

  var user = this.route('/:user', function(ctx) {
    return (
      <div>
        <a href={home()}>Home</a>
        <br />
        <a href={friends(ctx.params.user)}>See Friends</a>
      </div>
    );
  });
});

Reactivity

On the client, the render method of a component is run within a reactive computation. Whenever that computation is invalidated, the component will be re-rendered.

This is done by wrapping React.createClass(), and react components made through another mechanism may not act reactively.

Programmatically Changing Pages

If you want to change the current page in response to a javascript event (such as a button press), you have a few options. The function returned by this.route() has a method: go. Calling go and passing the same arguments that you would to the function returned by this.route() will redirect you to that page.

If you want to redirect to a specific URL, you can also call RouteCore.go(url).

Example

/** @jsx React.DOM */

ProjectPage = React.createClass({ ... }); 

NewProjectButton = React.createClass({
  newProject: function(e) {
    var project = ...;

    // Either of the following would work:
    Routes.project.go(project);
    // or
    RouteCore.go(Routes.project(project));
  },

  render: function() {
    return (<button onClick={this.newProject}>New Project!</button>);
  }
});

Routes = {};

RouteCore.map(function() {
  Routes.project = this.route('/projects/:project', ProjectPage);
});

Redirecting

Sometimes, you want to redirect the user to a different page. To do this simply call redirect(target_url) on the current page context. If you do this on the server, it will respond to the client with a 307 status code. On the client, page.js will be used to send the user to a different page.

Example

RouteCore.map(function() {
  var home = this.route('/', HomePage);

  this.route('/oldHome', function() {
    this.redirect(home());
  });
});

Custom Server Side Responses

Sometimes you want to respond with your own data on the server. On the server, the page context has two properties: request and response. These are the node HTTP request and response objects. You can call functions on them to directly send data to the client.

RouteCore will recognise if you call response.end(), and will not try to send any further data.

Example

RouteCore.map(function() {
  if (Meteor.isServer) {
    this.route('/resource', function() {
      this.response.setHeader('Content-Type', 'application/json');
      this.response.end(JSON.stringify({
        data: 'WOO'
      }));
    });
  }
});

Blaze Rendering Integration

There are some really awesome components (such as {{> loginButtons}}) which have been made for Meteor's Blaze rendering engine, which are not compatible with React and server side rendering.

RouteCore contains a simple component to allow you to use these components.

Calling RouteCore.BlazeComponent(component) creates a React component which, on the client, will contain the blaze component. A string can also be passed as the component argument. If this is the case, the template with that name will be used.

NOTE The released version of Meteor still only bundles Spark, Meteor's old rendering engine. The integration does not support Spark, and requires at least blaze-rc0. To upgrade your project to blaze-rc0, run meteor update --release blaze-rc0.

Example

template.html

<template name="integration">
  <p>I got this value from react: {{value}}</p>

  {{> loginButtons}}
</template>

component.jsx

/** @jsx React.DOM */

var Integration = RouteCore.BlazeComponent('integration');

var OtherComponent = React.createClass({
  render: function() {
    return <Integration value='Sending data!' />
  }
}):

License

(The MIT License)

Copyright (c) 2013 Michael Layzell

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

meteor-routecore's People

Contributors

mystor avatar jantimon avatar trusktr avatar thomporter avatar

Stargazers

Nick avatar Max Bittker avatar Rafael Rozon avatar Bart Louwers avatar Dillon Amadeo avatar Prem Rose avatar borjarobles avatar Halil Ertekin avatar Nick Reese avatar Fabio Dias Rollo avatar Feng Qiu avatar  avatar Zachary Dixon avatar  avatar Guido avatar Christopher Stingl avatar Patrick Lienau avatar Maneeshg avatar Andreas Stuhlmüller avatar Mikhail Proniushkin avatar  avatar Leon avatar Gaurav avatar David Wabnitz avatar Chet Corcos avatar Biserov Maksim avatar Tyler Hellner avatar Clément Pigeon avatar chris avatar Dmitry Novikov avatar  avatar Michael Rawlings avatar Tim Brandin avatar Maximilian Stroh avatar Venelin avatar Sven Roeterdink avatar  avatar Selem Delul avatar  avatar Jonathan James avatar Dmitry Polushkin avatar shekar73 avatar Adam avatar Joost avatar Derek Braid  avatar Masaru Itoh avatar Hector Romo avatar  avatar Keith Hörling avatar TrueMagic avatar Quentin Bramas avatar Lance Pollard avatar Ben McMahen avatar Kevin Quoc Truong avatar Radu Ciocan avatar Bozhao avatar  avatar Pahan Sarathchandra avatar  avatar Charleno Pires avatar Raj Anand avatar Arunoda Susiripala avatar Robin Vivant avatar Pantelis Koukousoulas avatar Patrick Violette avatar JK avatar  avatar Cooper Maruyama avatar Helder S Ribeiro avatar Joe avatar Lieuwe Rooijakkers avatar David Thompson avatar stringparser avatar  avatar Ritik Malhotra avatar crapthings avatar Rik avatar Jan Laußmann avatar Dave Clayton avatar pan avatar Long Nguyen avatar Maxime Quandalle avatar Rahul avatar George Paley avatar

Watchers

pan avatar Gaurav avatar James Cloos avatar  avatar Xianliang Wu avatar Praney Behl avatar Patrick Lienau avatar stringparser avatar Venelin avatar Syed Peer avatar  avatar  avatar

meteor-routecore's Issues

Working Example?

Hi,
Thank you for your effort, greatly appreciate it.

Just being new to reactjs and jsx, I was wondering if there was a working sample/example for this package it would be really great.

Thanks,
Praney

Reactivity while rendering Components

Component rendering is currently run within a computation on the client. However, React can re-render the component while not in a reactive computation, which means that using reactive data sources in component methods has inconsistent results.

The component rendering should be probably be non-reactive, and a mixin should be added to enable reactive state within components, in a similar style to react-meteor.

Don't embed react 0.8.0 in the bundle, use the react-meteor install instead?

https://github.com/reactjs/react-meteor

I can use react with react-bootstrap here, but as soon as I add routecore things break.

/Users/mtozer/.meteor/tools/c2a0453c51/lib/node_modules/fibers/future.js:173
throw(ex);
^
TypeError: Cannot read property 'name' of undefined
at /Users/mtozer/.meteor/tools/c2a0453c51/tools/packages.js:750:28
at Function..each..forEach (/Users/mtozer/.meteor/tools/c2a0453c51/lib/node_modules/underscore/underscore.js:87:22)
at /Users/mtozer/.meteor/tools/c2a0453c51/tools/packages.js:745:9
at Array.forEach (native)
at Function..each..forEach (/Users/mtozer/.meteor/tools/c2a0453c51/lib/node_modules/underscore/underscore.js:79:11)
at _.extend._allHandlers (/Users/mtozer/.meteor/tools/c2a0453c51/tools/packages.js:744:7)
at .extend.registeredExtensions (/Users/mtozer/.meteor/tools/c2a0453c51/tools/packages.js:768:24)
at slice.getSourcesFunc (/Users/mtozer/.meteor/tools/c2a0453c51/tools/packages.js:1713:41)
at .extend.build (/Users/mtozer/.meteor/tools/c2a0453c51/tools/packages.js:279:17)
at /Users/mtozer/.meteor/tools/c2a0453c51/tools/packages.js:1088:13
at Array.forEach (native)
at Function.
.each.
.forEach (/Users/mtozer/.meteor/tools/c2a0453c51/lib/node_modules/underscore/underscore.js:79:11)
at _.extend.build (/Users/mtozer/.meteor/tools/c2a0453c51/tools/packages.js:1087:7)
at _.extend.getForApp (/Users/mtozer/.meteor/tools/c2a0453c51/tools/library.js:285:9)
at /Users/mtozer/.meteor/tools/c2a0453c51/tools/bundler.js:1762:25
at Object.capture (/Users/mtozer/.meteor/tools/c2a0453c51/tools/buildmessage.js:191:5)
at Object.exports.bundle (/Users/mtozer/.meteor/tools/c2a0453c51/tools/bundler.js:1697:31)
at _.extend._runOnce (/Users/mtozer/.meteor/tools/c2a0453c51/tools/run-app.js:396:32)
at _.extend._fiber (/Users/mtozer/.meteor/tools/c2a0453c51/tools/run-app.js:520:28)
at /Users/mtozer/.meteor/tools/c2a0453c51/tools/run-app.js:340:12

I tried removing it myself but couldn't work out the best way...

Running the todomvc demo.

I tried cloning the todomvc repo, switch to the routecore branch, went into the routecore demo folder, then

 ❯❯❯ meteor                                                                                          [20:53:26]
[[[[[ ~/test/todomvc/labs/architecture-examples/meteor-routecore ]]]]]

=> Started proxy.
=> Meteor 1.0.1 is available. Update this project with 'meteor update'.
=> Started MongoDB.
=> Errors prevented startup:

While building the application:
error: no such package: 'routecore'

=> Your application has errors. Waiting for file change.
^C
>>> elapsed time 1m59s

 ❯❯❯ meteor update                                                                                   [20:55:28]
This project is at the latest release which is compatible with your
current package constraints.

/Users/josephpea/.meteor/packages/meteor-tool/.1.0.36.1jn84sd++os.osx.x86_64+web.browser+web.cordova/meteor-to
ol-os.osx.x86_64/dev_bundle/lib/node_modules/fibers/future.js:173
                                                throw(ex);
                                                      ^
Error: unknown package: routecore
    at throwConstraintSolverError (packages/constraint-solver/resolver.js:246)
    at ConstraintSolver.Resolver.resolve (packages/constraint-solver/resolver.js:193)
    at ConstraintSolver.PackagesResolver.resolve (packages/constraint-solver/constraint-solver.js:263)
    at /Users/josephpea/.meteor/packages/meteor-tool/.1.0.36.1jn84sd++os.osx.x86_64+web.browser+web.cordova/me
teor-tool-os.osx.x86_64/tools/catalog.js:327:32
    at /Users/josephpea/.meteor/packages/meteor-tool/.1.0.36.1jn84sd++os.osx.x86_64+web.browser+web.cordova/me
teor-tool-os.osx.x86_64/tools/buildmessage.js:338:18
    at _.extend.withValue (/Users/josephpea/.meteor/packages/meteor-tool/.1.0.36.1jn84sd++os.osx.x86_64+web.br
owser+web.cordova/meteor-tool-os.osx.x86_64/tools/fiber-helpers.js:112:14)
    at /Users/josephpea/.meteor/packages/meteor-tool/.1.0.36.1jn84sd++os.osx.x86_64+web.browser+web.cordova/me
teor-tool-os.osx.x86_64/tools/buildmessage.js:331:34
    at _.extend.withValue (/Users/josephpea/.meteor/packages/meteor-tool/.1.0.36.1jn84sd++os.osx.x86_64+web.br
owser+web.cordova/meteor-tool-os.osx.x86_64/tools/fiber-helpers.js:112:14)
    at /Users/josephpea/.meteor/packages/meteor-tool/.1.0.36.1jn84sd++os.osx.x86_64+web.browser+web.cordova/me
teor-tool-os.osx.x86_64/tools/buildmessage.js:329:23
    at _.extend.withValue (/Users/josephpea/.meteor/packages/meteor-tool/.1.0.36.1jn84sd++os.osx.x86_64+web.br
owser+web.cordova/meteor-tool-os.osx.x86_64/tools/fiber-helpers.js:112:14)
    at Object.enterJob (/Users/josephpea/.meteor/packages/meteor-tool/.1.0.36.1jn84sd++os.osx.x86_64+web.brows
er+web.cordova/meteor-tool-os.osx.x86_64/tools/buildmessage.js:303:26)
    at _.extend.resolveConstraints (/Users/josephpea/.meteor/packages/meteor-tool/.1.0.36.1jn84sd++os.osx.x86_
64+web.browser+web.cordova/meteor-tool-os.osx.x86_64/tools/catalog.js:320:30)
    at /Users/josephpea/.meteor/packages/meteor-tool/.1.0.36.1jn84sd++os.osx.x86_64+web.browser+web.cordova/me
teor-tool-os.osx.x86_64/tools/commands-packages.js:1965:36
    at /Users/josephpea/.meteor/packages/meteor-tool/.1.0.36.1jn84sd++os.osx.x86_64+web.browser+web.cordova/me
teor-tool-os.osx.x86_64/tools/buildmessage.js:250:13
    at _.extend.withValue (/Users/josephpea/.meteor/packages/meteor-tool/.1.0.36.1jn84sd++os.osx.x86_64+web.br
owser+web.cordova/meteor-tool-os.osx.x86_64/tools/fiber-helpers.js:112:14)
    at /Users/josephpea/.meteor/packages/meteor-tool/.1.0.36.1jn84sd++os.osx.x86_64+web.browser+web.cordova/me
teor-tool-os.osx.x86_64/tools/buildmessage.js:243:29
    at _.extend.withValue (/Users/josephpea/.meteor/packages/meteor-tool/.1.0.36.1jn84sd++os.osx.x86_64+web.br
owser+web.cordova/meteor-tool-os.osx.x86_64/tools/fiber-helpers.js:112:14)
    at /Users/josephpea/.meteor/packages/meteor-tool/.1.0.36.1jn84sd++os.osx.x86_64+web.browser+web.cordova/me
teor-tool-os.osx.x86_64/tools/buildmessage.js:241:18
    at _.extend.withValue (/Users/josephpea/.meteor/packages/meteor-tool/.1.0.36.1jn84sd++os.osx.x86_64+web.br
owser+web.cordova/meteor-tool-os.osx.x86_64/tools/fiber-helpers.js:112:14)
    at /Users/josephpea/.meteor/packages/meteor-tool/.1.0.36.1jn84sd++os.osx.x86_64+web.browser+web.cordova/me
teor-tool-os.osx.x86_64/tools/buildmessage.js:232:23
    at _.extend.withValue (/Users/josephpea/.meteor/packages/meteor-tool/.1.0.36.1jn84sd++os.osx.x86_64+web.br
owser+web.cordova/meteor-tool-os.osx.x86_64/tools/fiber-helpers.js:112:14)
    at Object.capture (/Users/josephpea/.meteor/packages/meteor-tool/.1.0.36.1jn84sd++os.osx.x86_64+web.browse
r+web.cordova/meteor-tool-os.osx.x86_64/tools/buildmessage.js:231:19)
    at main.registerCommand.name [as func] (/Users/josephpea/.meteor/packages/meteor-tool/.1.0.36.1jn84sd++os.
osx.x86_64+web.browser+web.cordova/meteor-tool-os.osx.x86_64/tools/commands-packages.js:1964:31)
    at /Users/josephpea/.meteor/packages/meteor-tool/.1.0.36.1jn84sd++os.osx.x86_64+web.browser+web.cordova/me
teor-tool-os.osx.x86_64/tools/main.js:1353:23

Any ideas on what to do? The README still is using mrt. xD

Post requests

There doesn't seem to be a way to receive post requests server side. This is a problem when integrating with payment solutions etc.

Blaze views.

I'd like to confirm: this entirely replaces the Blaze engine right? If so, what are the pros and cons?

JSX transformation not working

Hi there,

I've been using ReactJS a lot at work so was excited about this project. :)

I'm currently having trouble as my JSX file doesn't seem to get transformed and/or be found by Meteor. I have a components directory with home.jsx in it with this code:

/** @jsx React.DOM */
var Home = React.createClass({
    render: function() {
        return (
            <div>
                <h1>Home</h1>
        <a href={home()}>Home</a>
            </div>
        );
    }
});

And in the root of my project a router:

RouteCore.map(function() {
  this.route('/', function(ctx) {
    return Home({});
  });
});

But I get this when I hit /:

W20140306-08:27:36.576(1)? (STDERR) Error while rendering path: / ; error: ReferenceError: Home is not defined

Any ideas what might be happening? This is with an existing project that also has Iron-Router, so I'm not sure if it might be conflicting.

Routing after a button click.

I have the following

Routes = {};

RouteCore.map(function() {
Routes.home = this.route('/', function(ctx) {
return (



);
});

Routes.project = this.route('/projects/:project', function(ctx) {
    return (
        <Layout>
            <Editor filter="active" project=ctx.params.project />
        </Layout>
    );
});

});

var CreateProjectButton = React.createClass({
render: function () {
return(

);
},
addProject: function() {
var project = Projects.insert({name:"new proj"});
Routes.project .....????
},

});

I'm trying to route to the new project page after it has been created when the user clicks the button (I can see the project being inserted correctly). The documentation isn't clear on how to go about this with react. With iron router I would have said something like Router.go("projects", {_id: project});

Is this possible?

Not rendering server side

Hey, great work on RouteCore, it was exactly what I was looking for. The routing is working well, but I'm having some problems getting react rendering to work server side. I'm fairly new to Meteor so this might not be an issue with RouteCore, but I'm not sure where else to ask. Basically, the initial source looks like this:

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
  __fast_render_config = {"subscriptions":{},"serverRoutePath":"/sv/","subscriptionIdMap":{},"loadedSubscriptions":{}}
</script>

  <link rel="stylesheet" type="text/css" class="__meteor-css__" href="/ff3f5021068dc3ed03f09c93cbf109ced1be914f.css">

<script type="text/javascript">__meteor_runtime_config__ = {"meteorRelease":"[email protected]","ROOT_URL":"http://localhost:3000/","ROOT_URL_PATH_PREFIX":"","autoupdateVersion":"31d59e6f3166c778b0f2f84a51804c14ddd0a998","autoupdateVersionRefreshable":"8b2b0c043a0ac0a98c537170b9cf92851760c6c8"};</script>

  <script type="text/javascript" src="/packages/underscore.js?0a80a8623e1b40b5df5a05582f288ddd586eaa18"></script>
  ... more scripts

<title>...</title>
  <script src="http://www.youtube.com/player_api"></script>
<script type="text/javascript">
  if(typeof Package['meteorhacks:fast-render'].__init_fast_render == 'function') {
    Package['meteorhacks:fast-render'].__init_fast_render("%7B%22collectionData%22:%7B%7D%7D")
  }
</script>
</head>
<body>

</body>
</html>

collectionData seems to be empty, and nothing is rendered in body on initial load. Any idea what I've done wrong?

Don't call methods in React Class

upConter don't call by click button

/** @jsx React.DOM */
var layout = React.createClass({
    upCounter: function(e){
        console.log(1);
    },
    render: function(){
        return (
            <div>
                <h1>Welcome to Meteor!</h1>

                <button onclick={this.upCounter}>Click Me</button>
            </div>
            );
    }
});

RouteCore.map(function () {
    var home = this.route('/', layout);
});]]

Precompiled React code does not work.

I have been trying to use React Code of an existing library.
However it seems like routecore does not provide a valid React object.

I could reproduce the errors with the following example:

Example routes.jsx

/** @jsx React.DOM */
RouteCore.map(function () {
  this.route('/', function () {
    var x = React.createClass({
      render: function () {
        return React.createElement("div", {className: "bg"})
      }
    });
    return (<x/>);
  });
});

Server Side:
TypeError: Object #<Object> has no method 'createElement' at [object Object].React.createClass.render

Client Side:
Uncaught Error: Invariant Violation: _registerComponent(...): Target container is not a DOM element.

Is there any workaround?

optional params not working on server side

hi @mystor
it seems optional params are not working in server side code.

sample code

RouteCore.map(function() {
  this.route('/:required/:optional?', function(){
    //code
  }
});

If I visited http://localhost:3000/required/optional it is working. but for http://localhost:3000/required/ it is not working.

onClick doenst work

I was searching on every site ... no result was fix my problem. Can Someone help me ?
Its just a basic example but it didnt work. Why?
The Programm is rendering well but nothing happens .. :-(

/** @jsx React.DOM */

RouteCore.bindGlobals();

var Clicker = React.createClass({
    handleClick: function(e) {
        console.log("click");
    },
    render: function() {
        return (
            <button onClick={this.handleClick}> Click me</button>
        );
    }
});

var Page = React.createClass({
    render: function(){
        return (<Clicker />)
    }
});

RouteCore.map(function () {
        this.route('/page', function() {
            return (<Page />);
        });
});

waitOn equivalent

In iron-router I would have done something like this to ensure my subscriptions are ready before rendering.

this.route('event', {
    path: '/event/:_id',
    waitOn: function () {
        //Meteor.subscribe('event', this.params._id);
        Meteor.subscribe('countries');
        Meteor.subscribe('players', this.params._id);
        Meteor.subscribe('votes', this.params._id);
        Meteor.subscribe('results', this.params._id);
        return Meteor.subscribe('events');
    },
    data: function () {
        var anEvent = Events.findOne(this.params._id);
        return anEvent;  
    },
    action: function() {
        if (this.ready()) {
            this.render()  
        } else {
            this.render('loading');
        }
    }
});

I've dug a bit into the documentation and the example code, and even the source, but don't see how to do this. Is this possible yet?

Preserve Meteor.user & Meteor.userId on server

RouteCore overwrites Meteor.user and Meteor.userId on server when bindGlobals is run. Meteor provides these functions for use in Meteor methods.

They should no longer be overridden, and instead the same mechanism as Meteor methods should be used.

Does each route's React class take over as the root element?

So if I have

  var home = this.route('/', HomePage);
  var friends = this.route('/:user/friends', FriendsPage);

it seems like switch from / to /:user/friends will make the root element change from HomePage to FriendsPage, and so if you wanted to have like a common header with tabs for example, then you'd have to use that Header component in both HomePage and FriendsPage.

Is there a different pattern to use so that a Header element instance only need to be instantiated once, and a route (changed by switching tabs for example) would only change the content of the tab area?

Cordova compatibility

Great package! Love the server-side rendering.

Is this intended to work on Cordova? It is not working for me. I am just getting a blank screen. To reproduce, create an empty meteor project with a single file (e.g. routes.jsx):

/** @jsx React.DOM */

RouteCore.map(function() {
  this.route('/', function() {
    return (
      <div>
        hello
      </div>
    );
  });
});

This works fine in a browser. Then, run in the simulator by adding the platform (meteor add-platform ios) and running meteor run ios (More Cordova instructions here).

It looks like meteor-routecore has to get started on the server, but never does in a Cordova app.

Modularizing code

How would we split app.jsx into separate files (i.e. import React classes that are exported from other files)?

Clients generating identical session values as server.

In the README, it says

NOTE RouteCore does not send the session values which are generated on the server to the client. When the client renders code for the first time, it is expected that it will generate identical session values.

Can you explain this a little more? Is there some handling that we need to implement? Or is this already handled if we stick to the API?

Improve error message for no context on server

console.log(RouteCore.context());

in main.jsx

/home/efrem/.meteor/packages/meteor-tool/.1.0.40.1ef5dzv++os.linux.x86_64+web.browser+web.cordova/meteor-tool-os.linux.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:173
W20150207-11:39:13.913(4)? (STDERR)                         throw(ex);
W20150207-11:39:13.913(4)? (STDERR)                               ^
W20150207-11:39:14.000(4)? (STDERR) TypeError: Cannot read property 'context' of undefined
W20150207-11:39:14.000(4)? (STDERR)     at Object.context (packages/mystor:routecore/context-server.js:89:1)
W20150207-11:39:14.000(4)? (STDERR)     at app/main.jsx.js:3:23
W20150207-11:39:14.000(4)? (STDERR)     at app/main.jsx.js:7:3
W20150207-11:39:14.000(4)? (STDERR)     at /home/efrem/WebstormProjects/test_meteor/.meteor/local/build/programs/server/boot.js:205:10
W20150207-11:39:14.001(4)? (STDERR)     at Array.forEach (native)
W20150207-11:39:14.001(4)? (STDERR)     at Function._.each._.forEach (/home/efrem/.meteor/packages/meteor-tool/.1.0.40.1ef5dzv++os.linux.x86_64+web.browser+web.cordova/meteor-tool-os.linux.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
W20150207-11:39:14.001(4)? (STDERR)     at /home/efrem/WebstormProjects/test_meteor/.meteor/local/build/programs/server/boot.js:116:5

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.