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
| class Account { | |
| private _observers: Observers = new Observers(); | |
| constructor(private _type: string, private _balance: number) { | |
| this._observers.subscribe(new Observer(`${this._type} balance`)); | |
| } | |
| get balance() { | |
| return this._balance; | |
| }; |
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
| const fee = (feeAmount: number) => { | |
| return function ( | |
| target: Object, | |
| propertyName: string, | |
| propertyDescriptor: PropertyDescriptor, | |
| ) { | |
| const originalSetter = propertyDescriptor.set; | |
| propertyDescriptor.set = function (next) { | |
| const newBalance = next - feeAmount; |
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
| class Account { | |
| private _observers: Observers = new Observers(); | |
| constructor(private _type: string, private _balance: number) { | |
| this._observers.subscribe(new Observer(`${this._type} balance`)); | |
| } | |
| get balance() { | |
| return this._balance; | |
| }; |
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 ObserverCallback = (newValue: any) => void; | |
| class Observer { | |
| constructor(private _subject: string, private _callback?: ObserverCallback) { | |
| } | |
| get subject() { | |
| return this._subject; | |
| } |
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
| interface ITransactionDelegate { | |
| deduct(amount: number, context: Account): void; | |
| } | |
| class Transaction implements ITransactionDelegate { | |
| deduct = (amount: number, context: Account) => context.balance = context.balance - amount; | |
| } | |
| class Account { | |
| constructor(private _type: string, private _balance: number) { |
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, { Component, ReactNode } from 'react'; | |
| type Props = { | |
| whatAnimal:string, | |
| }; | |
| export class Animal extends Component<Props> { | |
| componentWillMount() { | |
| // Class Component Lifecycle | |
| } |
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, { ReactElement } from 'react'; | |
| interface Customer { | |
| firstName: string; | |
| } | |
| type Props = { | |
| customer: Customer; | |
| } |
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
| // create a regular div and span elements | |
| const div = document.createElement('div'); | |
| const span = document.createElement('span'); | |
| span.id = 'span_id'; | |
| // appending the span element under the div | |
| div.appendChild(span); | |
| // append the div into the DOM | |
| document.body.appendChild(div); | |
| // will output HTMLDivElement {} |
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 'reflect-metadata'; | |
| import { ApolloServer } from 'apollo-server-express'; | |
| import express from 'express'; | |
| import { buildSchema } from 'type-graphql'; | |
| import { init_db } from './database/init_db'; | |
| import { Resolvers } from './schema/Resolvers'; | |
| const main = async() => { | |
| await init_db(); |
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": "sqlite", | |
| "database": "./src/database/database.sqlite3", | |
| "entities": [ | |
| "./src/models/index.ts" | |
| ] | |
| } |