Skip to content

Instantly share code, notes, and snippets.

View tkssharma's full-sized avatar
🎯
only JS

codewithtkssharma tkssharma

🎯
only JS
View GitHub Profile
import React, { useState, useMemo } from "react";
const fibonacci = n => {
if (n <= 1) {
return 1;
}
return fibonacci(n - 1) + fibonacci(n - 2);
};
const MemoComponent = () => {
@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(
@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$;
<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>
@Component({
selector: 'app-books',
templateUrl: './books.component.html'
})
export class BooksComponent implements OnDestroy, OnInit {
private ngUnsubscribe = new Subject();
constructor(private booksService: BookService) { }
ngOnInit() {
{
arrowParens: 'avoid',
bracketSpacing: true,
htmlWhitespaceSensitivity: 'css',
jsxBracketSameLine: false,
printWidth: 80,
proseWrap: 'preserve',
requirePragma: false,
semi: true,
singleQuote: true,
@tkssharma
tkssharma / setstate
Created December 2, 2020 06:29 — forked from tkskumar/setstate
```
setState()
- is Asynchronous
- can have a function as a parameter instead of object
- can accepts a Callback function as a second argument (optional)
- does not return promise
```
function updateState(){
this.setState({load: true}, () => {
version: '3.5'
services:
zota_mongo:
volumes:
- mongo_data:/data/configdb
- mongo_data:/data/mysql
gateway:
volumes:
- ./proxy/default.conf:/etc/nginx/conf.d/default.conf:ro
- ./proxy/ssl:/etc/nginx/ssl:ro
version: '3.5'
services:
gateway:
image: nginx:1.11
ports:
- 88:80
- 443:443
depends_on:
- zota_car
- zota_company
FROM node:carbon
WORKDIR /usr/src/app
ARG GIT_TOKEN
COPY package.json package-lock.json .npmrc ./
RUN npm install
RUN rm -f .npmrc
# Add your source files
COPY . .
EXPOSE 3000
RUN npm run build