This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const binarySearch = (items, x) => { | |
let low = 0 | |
let high = items.length - 1 | |
while (low <= high) { | |
const mid = parseInt((low + high) / 2, 10) | |
const current = items[mid] | |
if (current > x) { | |
high = mid - 1 | |
} else if (current < x) { | |
low = mid + 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function* linkTo({ payload }) { | |
const { route, params } = payload | |
const action = ['Products', 'Configuration', 'Profile'].includes(route) | |
? NavigationActions.reset({ | |
index: 0, | |
key: route, | |
actions: [NavigationActions.navigate({ routeName: route, params })], | |
}) | |
: NavigationActions.navigate({ routeName: route, params }) | |
yield put(action) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react' | |
import { connect } from 'react-redux' | |
import _ from 'lodash' | |
export const renderer = (route, Wrapped) => | |
class extends Component { | |
shouldComponentUpdate(props) { | |
if (!props.render || this.props.currentRoute === 'DrawerOpen') { return false } | |
const thisProps = JSON.stringify(_.omit(this.props, ['nav', 'navigation', 'screenProps'])) | |
const nextProps = JSON.stringify(_.omit(props, ['nav', 'navigation', 'screenProps'])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ApolloClient, {createNetworkInterface} from 'apollo-client' | |
import {addTypenameToSelectionSet} from 'apollo-client/queries/queryTransform' | |
import baseURL from './url' // we could use a string url here for example localhost:port/ | |
const getLoginToken = function () { | |
return window.localStorage['Meteor.loginToken'] | |
} | |
export const createMeteorNetworkInterface = () => { | |
let uri = baseURL + '/graphql' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Resolvers as Auth} from 'meteor/nicolaslopezj:apollo-accounts' | |
import addTodo from './addTodo' | |
import toggleCompleted from './toggleCompleted' | |
export default { | |
...Auth(), | |
addTodo, | |
toggleCompleted | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Todos} from '../../../../lib/Collections' | |
export default function (root, options, context) { | |
console.log(options) | |
if (!context.userId) { | |
throw new Error('Unknown User (not logged in)') | |
} | |
// validate the todo belongs to the user | |
const todo = Todos.findOne({$and: [{_id: options.todoId}, {owner: context.userId}]}) | |
// if not found throw Error | |
if (!todo) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {SchemaMutations as Auth} from 'meteor/nicolaslopezj:apollo-accounts' | |
import addTodo from './addTodo.graphql' | |
import toggleCompleted from './toggleCompleted.graphql' | |
export default ` | |
type Mutation { | |
${Auth()} | |
${addTodo} | |
${toggleCompleted} | |
} | |
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Query from './Query' | |
import Mutation from './Mutations' | |
import User from './User' | |
export default { | |
...User, | |
Query, | |
Mutation | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Todos} from '../../../../lib/Collections' | |
export default { | |
User: { | |
todos (user) { | |
return Todos.find({owner: user._id}).fetch() | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Todos} from '../../../../lib/Collections' | |
export default function (root, options, context) { | |
// it wont let anonymous users create a todo | |
if (!context.userId) { | |
throw new Error('Unknown User (not logged in)') | |
} | |
// pack the todo adding the userId as the owner id | |
const newTodo = { | |
text: options.text, |
NewerOlder