Skip to content

Instantly share code, notes, and snippets.

View kamilkisiela's full-sized avatar
🕶️
Kamil Kisiela

Kamil Kisiela kamilkisiela

🕶️
Kamil Kisiela
View GitHub Profile
import { createLoona, LoonaProvider } from '@loona/react';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { ApolloClient } from 'apollo-client';
import { ApolloProvider } from 'react-apollo';
// Instance of a cache
const cache = new InMemoryCache();
// Create Loona Link
export class BooksState {
// It does nothing except creating a new book
@mutation('addBook')
addBook(args, context) {
return {
id: generateRandomId(),
title: args.title,
__typename: 'Book',
};
}
import {effect} from '@loona/react';
export class BooksState {
@effect(AddBook)
bookAdded(action, context) {
console.log(action);
// outputs:
// {
// type: '[Books] Add',
// title: '...'
//
// Using Action component
//
import { Action } from '@loona/react';
export const NewBook = () => (
<Action>
{dispatch => (
<button onClick={() => dispatch(new AddBook('Harry Potter'))}>
export class AddBook {
static type = '[Books] Add';
constructor(public title: string) {}
}
import { mutation } from '@loona/react';
export class BooksState {
@mutation('addBook')
addBook(args, context) {
// our new book
const book = {
id: generateRandomId(),
title: args.title,
__typename: 'Book',
import {state} from '@loona/react';
@state({
defaults: {
books: []
}
})
export class BooksState {}
import {state} from '@loona/react';
@state()
export class BooksState {}
import {Mutation} from '@loona/react';
const ADD_BOOK = gql`
mutation AddNewBook($title: String!) {
addBook(title: $title) @client {
id
title
}
}
`;
import React from 'react';
import { Query } from '@loona/react';
import { List } from '../common/List';
const ALL_BOOKS = gql`
query GetAllBooks {
books @client {
id
title