This file contains hidden or 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 {state} from '@loona/react'; | |
@state() | |
export class BooksState {} |
This file contains hidden or 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 {state} from '@loona/react'; | |
@state({ | |
defaults: { | |
books: [] | |
} | |
}) | |
export class BooksState {} |
This file contains hidden or 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 { mutation } from '@loona/react'; | |
export class BooksState { | |
@mutation('addBook') | |
addBook(args, context) { | |
// our new book | |
const book = { | |
id: generateRandomId(), | |
title: args.title, | |
__typename: 'Book', |
This file contains hidden or 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 class AddBook { | |
static type = '[Books] Add'; | |
constructor(public title: string) {} | |
} |
This file contains hidden or 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
// | |
// Using Action component | |
// | |
import { Action } from '@loona/react'; | |
export const NewBook = () => ( | |
<Action> | |
{dispatch => ( | |
<button onClick={() => dispatch(new AddBook('Harry Potter'))}> |
This file contains hidden or 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 {effect} from '@loona/react'; | |
export class BooksState { | |
@effect(AddBook) | |
bookAdded(action, context) { | |
console.log(action); | |
// outputs: | |
// { | |
// type: '[Books] Add', | |
// title: '...' |
This file contains hidden or 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 class BooksState { | |
// It does nothing except creating a new book | |
@mutation('addBook') | |
addBook(args, context) { | |
return { | |
id: generateRandomId(), | |
title: args.title, | |
__typename: 'Book', | |
}; | |
} |
This file contains hidden or 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 { 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 |
This file contains hidden or 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
new GraphQLObjectType({ | |
name: 'Post', | |
fields: { | |
id: { | |
type: GraphQLString | |
}, | |
text: { | |
type: GraphQLString | |
} | |
} |
This file contains hidden or 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
type Post { | |
id: String | |
text: String | |
} |