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
{ | |
arrowParens: 'avoid', | |
bracketSpacing: true, | |
htmlWhitespaceSensitivity: 'css', | |
jsxBracketSameLine: false, | |
printWidth: 80, | |
proseWrap: 'preserve', | |
requirePragma: false, | |
semi: true, | |
singleQuote: true, |
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
@Component({ | |
selector: 'app-books', | |
templateUrl: './books.component.html' | |
}) | |
export class BooksComponent implements OnDestroy, OnInit { | |
private ngUnsubscribe = new Subject(); | |
constructor(private booksService: BookService) { } | |
ngOnInit() { |
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
<div class="container"> | |
<div class="block"> | |
<h1>List of users</h1> | |
<ul *ngIf="userWithPost$ | async as userList"> | |
<li *ngFor="let user of userList"> | |
<a href="#" (click)="selectUser(user.id)">{{user.username}}</a> | |
</li> | |
</ul> | |
</div> |
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
@Component({ | |
selector: 'my-app', | |
templateUrl: './app.component.html', | |
styleUrls: [ './app.component.css' ], | |
changeDetection: ChangeDetectionStrategy.OnPush | |
}) | |
export class AppComponent { | |
user$ = this.usersService.user$; | |
userWithPost$ = this.usersService.userWithPost$; | |
selectedUser$ = this.usersService.selectedUser$; |
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
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class UsersService { | |
constructor(private http: HttpClient, private postsService: PostsService) { } | |
private userSelectedAction = new Subject<number>(); | |
private usersUrl = 'https://jsonplaceholder.typicode.com/users'; | |
user$ = this.http.get<Users>(this.usersUrl).pipe(shareReplay()); | |
userWithPost$ = combineLatest( |
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 React, { useState, useMemo } from "react"; | |
const fibonacci = n => { | |
if (n <= 1) { | |
return 1; | |
} | |
return fibonacci(n - 1) + fibonacci(n - 2); | |
}; | |
const MemoComponent = () => { |
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
function LocalStorageHook() { | |
const [count, setCount] = useState(() => { | |
let value; | |
try { | |
value = JSON.parse( | |
window.locastorage.getItem('count') || '0' | |
) | |
} catch (e) { |
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 React from 'react'; | |
import gql from 'graphql-tag'; | |
import { Query } from 'react-apollo'; | |
import SpacexComponent from './Space'; | |
import Mock from './Space/mock'; | |
const GET_SPACEX_DATA = gql` | |
{ | |
launchesPast(limit: 10) { | |
mission_name |
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 { ApolloClient } from 'apollo-client'; | |
import { HttpLink } from 'apollo-link-http'; | |
import { ApolloLink, concat } from 'apollo-link'; | |
const httpLink = new HttpLink({ uri: '/graphql' }); | |
// registering middlewares [authMiddleware, otherMiddleware ] | |
const authMiddleware = new ApolloLink((operation, forward) => { | |
// add the authorization to the headers | |
operation.setContext({ | |
headers: { | |
authorization: localStorage.getItem('token') || null, |
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 React from "react"; | |
import ReactDOM from "react-dom"; | |
const ToDoContext = React.createContext(); | |
class ToDoList extends React.Component { | |
state = { | |
list: [], | |
todo: "" | |
}; | |
createNewToDoItem = () => { | |
this.setState(({ list, todo }) => ({ |