Skip to content

Instantly share code, notes, and snippets.

View spencercarli's full-sized avatar

Spencer Carli spencercarli

View GitHub Profile
@spencercarli
spencercarli / posts.js
Created February 12, 2016 02:04
Easily Connect React Native to a Meteor Server - Add Functionality to the Meteor App - posts.js
Posts = new Mongo.Collection('posts');
Meteor.methods({
'addPost': function() {
Posts.insert({title: 'Post ' + Random.id()});
},
'deletePost': function() {
let post = Posts.findOne();
if (post) {
@spencercarli
spencercarli / app.js
Created February 12, 2016 02:05
Easily Connect React Native to a Meteor Server - Add Functionality to the Meteor App - app.js
Meteor.startup(function() {
if (Posts.find().count() === 0) {
for (i = 1; i <= 10; i++) {
Posts.insert({title: 'Post ' + Random.id()});
}
}
});
Meteor.publish('posts', function() {
return Posts.find();
@spencercarli
spencercarli / home.html
Created February 12, 2016 02:06
Easily Connect React Native to a Meteor Server - Add Functionality to the Meteor App - home.html
<template name="home">
<h1>Post Count: {{count}}</h1>
<button id="increment">Increment</button>
<button id="decrement">Decrement</button>
</template>
@spencercarli
spencercarli / home.js
Created February 12, 2016 02:06
Easily Connect React Native to a Meteor Server - Add Functionality to the Meteor App - home.js
Template.home.onCreated(function() {
this.subscribe('posts');
});
Template.home.helpers({
count() {
return Posts.find().count();
}
});
@spencercarli
spencercarli / index.html
Created February 12, 2016 02:07
Easily Connect React Native to a Meteor Server - Add Functionality to the Meteor App - index.html
<head>
<title>meteor-app</title>
</head>
<body>
{{> home}}
</body>
@spencercarli
spencercarli / index.js
Created February 12, 2016 02:17
Easily Connect React Native to a Meteor Server - Setting up the React Native App - index.js
import React, {
View,
Text,
StyleSheet
} from 'react-native';
import Button from './button';
export default React.createClass({
getInitialState() {
@spencercarli
spencercarli / button.js
Created February 12, 2016 02:17
Easily Connect React Native to a Meteor Server - Setting up the React Native App - button.js
import React, {
View,
Text,
TouchableOpacity,
StyleSheet
} from 'react-native';
export default React.createClass({
render() {
let { text, onPress } = this.props;
@spencercarli
spencercarli / index.ios.js
Created February 12, 2016 02:17
Easily Connect React Native to a Meteor Server - Setting up the React Native App - index.ios.js
import React, {
AppRegistry,
Component
} from 'react-native';
import App from './app';
class RNApp extends Component {
render() {
return <App />;
@spencercarli
spencercarli / index.android.js
Created February 12, 2016 02:18
Easily Connect React Native to a Meteor Server - Setting up the React Native App - index.android.js
import React, {
AppRegistry,
Component
} from 'react-native';
import App from './app';
class RNApp extends Component {
render() {
return <App />;
@spencercarli
spencercarli / index.js
Created February 12, 2016 02:21
Easily Connect React Native to a Meteor Server - Connecting React Native App to Meteor - index.js
import React, {
View,
Text,
StyleSheet
} from 'react-native';
import Button from './button';
import DDPClient from 'ddp-client';
let ddpClient = new DDPClient();