Coder Social home page Coder Social logo

jsjaspreet / apollo-local-link-state-example Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 80 KB

Example of using Apollo Local Link State as a replacement of Redux

HTML 14.08% CSS 0.57% JavaScript 85.35%
graphql react tutorial apollo redux redux-saga replacement apollo-link

apollo-local-link-state-example's Introduction

Getting Started

$ yarn
$ yarn start

2/19/2018

I based this project off of create-react-app, so all you have to do is yarn and yarn start and the whole project is running. It uses GIPHY's public graphql API to randomly display memes, and uses apollo-local-link-state to keep a counter running of how many times you've clicked an "Add Meme" button on the page to figure out how many memes to show you (wait a few seconds in between clicking add meme, otherwise you'll get the same meme again).

The code in graphql/client I think is really similar to Redux, I think this clearly proves that you can replace vanilla redux with local link state, and if you're familiar with graphql, I suspect we'll see a lot of improvements keeping the mental model of how data access works both remotely and locally in the same graphql paradigm (ie I query data to figure out what it is, and mutate it to change it). No need to think about action creators and topics and normalizing data yourself in a redux store.

I thought more about redux-saga and looked through the typical usecases, I don't think especially with the addition of allowing async functions in the mutation resolver code that we'll really need it. I personally see the biggest reason to use Saga is to easily coordinate arbitrary asynchronous code blocks but I think it'll be a lot easier to reason about the codebase if we stick to basic async await and write individual blocks in separate functions that are used together for more complicated asynchronous actions.

This was pretty fun. As an aside, apollo-boost is a pretty nice way to get sane defaults out of the box when using Apollo Client and it was only merged like 5 days ago so whew we are really bleeding edge here! In any case, I won't really mind if we go forward with Redux and Saga, I understand this is probably a bigger change from most people being really comfortable with Redux, though I do think local-link-state + async await will handle 99% of our use cases for our client apps in a way that is also very tractable for developers to reason about.

apollo-local-link-state-example's People

Contributors

jsjaspreet avatar

Stargazers

 avatar

Watchers

 avatar

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.