Skip to content

Instantly share code, notes, and snippets.

View guzmonne's full-sized avatar

Guzman Monne guzmonne

  • Uruguay
  • Montevideo, Uruguay
View GitHub Profile
@guzmonne
guzmonne / index.js
Created March 27, 2017 01:23
Helper component to avoid a race condition between windows.
import React from 'react';
import ReactDOM from 'react-dom';
import Root from './containers/Root.js';
import configureStore from './store/configureStore.js'
import './_styles/index.css';
const Loading = () => (<h1>Loading...</h1>)
const store = configureStore()
@guzmonne
guzmonne / Click.js
Created March 27, 2017 01:20
Dummy component to test Apollo's integration
import React from 'react'
import {gql, graphql} from 'react-apollo'
import update from 'immutability-helper'
import Click from '../components/Click.js'
class ClickContainer extends React.Component {
state = {
message: '',
}
@guzmonne
guzmonne / 002_setting-up-apollo-and-redux.js
Created March 27, 2017 01:16
Setting up Apollo and Redux
// ---------------------------
// Apollo Client Configuration
// ---------------------------
import {ApolloClient, createNetworkInterface} from 'react-apollo'
export const client = new ApolloClient({
networkInterface: createNetworkInterface({
uri: 'http://localhost:3000/graphql'
}),
addTypename: true,
@guzmonne
guzmonne / 002_setting-up-apollo-and-redux.js
Created March 27, 2017 01:14
Redux and Apollo coniguration
// ---------------------------
// Apollo Client Configuration
// ---------------------------
import {ApolloClient, createNetworkInterface} from 'react-apollo'
export const client = new ApolloClient({
networkInterface: createNetworkInterface({
addTypename: true,
dataIdFromObject: (result) => (
result._id && result.__typename
@guzmonne
guzmonne / 002_ipc.js
Created March 27, 2017 01:08
Electon ipc example
// On the renderer side, we listen for the 'done' event, and for the close
// event. We also send the 'open' event when the graphql button is clicked.
ipc.on('open:graphql_window:done', (event) => {
console.log('open:graphql_window:done')
addClass(graphiql, 'hidden')
removeClass(graphiqlLoading, 'hidden')
})
ipc.on('close:graphql_window', (event) => {
console.log('close:graphql_window')
@guzmonne
guzmonne / 002_graphql_schema.js
Created March 27, 2017 00:59
Habitapp first graphql schema
const {merge, range, uniqueId} = require('lodash')
const {makeExecutableSchema} = require('graphql-tools')
const {
schema: clickSchema,
} = require('./clicks.schema.js')
let clicks = []
const rootSchema = [`
type Query {
@guzmonne
guzmonne / 002_server.js
Created March 27, 2017 00:56
Express server with GraphQL endpoint
const express = require('express')
const bodyParser = require('body-parser')
const cors = require('cors')
const {graphqlExpress, graphiqlExpress} = require('graphql-server-express')
const schema = require('../graphql/schema.js')
const PORT = 3000
const app = express()
@guzmonne
guzmonne / 002_server-window.js
Created March 27, 2017 00:31
Opens the server window
const {BrowserWindow} = require('electron')
const url = require('url')
const path = require('path')
/**
* @function serverWindow
* @description Opens the server window.
* @param {Function} onClose Function to call after a 'closed' event.
*/
function serverWindow(onClose=function(){}) {
@guzmonne
guzmonne / 002_server-window.js
Created March 27, 2017 00:28
Opens the server window
const {BrowserWindow} = require('electron')
const url = require('url')
const path = require('path')
/**
* @function serverWindow
* @description Opens the server window.
* @param {Function} onClose Function to call after a 'closed' event.
*/
function serverWindow(onClose=function(){}) {
@guzmonne
guzmonne / 002_create-windows.js
Created March 27, 2017 00:27
Function to open electron window
function createWindows() {
if (wins.server === null)
wins.server = serverWindow(() => wins.server = null)
if (wins.main === null)
wins.main = mainWindow(() => wins.main = null)
}