| prefix | meaning |
|---|---|
| create | creates information |
| get | retreives information |
| fetch | gets something from the network, doesn't store it or anything |
| load | gets something from the network and stores it somewhere |
| store | accepts a value and stores it somewhere |
| is | deals with a boolean state |
| handle | respond to some event |
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 CacheMap<T, A extends any[]> { | |
| items = new Map<string, T>() | |
| createItem: (key: string, ...args: A) => T | |
| constructor(itemProvider: (key: string, ...args: A) => T) { | |
| this.createItem = itemProvider | |
| } | |
| get(key: string, ...args: A) { | |
| const item = this.items.get(key) || this.createItem(key, ...args) |
Flow and TypeScript are both fantastic projects with a very noble and ambitious mission: to add static types to JavaScript. After working with the both of them extensively, I've come to the conclusion that, to no offense to the very many smart people working on Flow, there's little reason to choose it over TS for any new project going forward.
Reasons why I believe TS should be chosen over Flow:
- TS offers significantly more available type definitions for third-party libraries
- While the validity of this may depend on one's choice of libraries, I've never personally seen a project which had more Flow definitions than TS definitions available for its dependencies.
- TS offers very powerful features in its type system that are missing from Flow, like conditional types and argument spread types
- TS gives a stronger developer experience:
- Refactors:
- Go to definition (also available with Flow, but slower and doesn't always work)
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
| // *Model represents any piece of data | |
| class TrackModel { | |
| constructor(public data) { | |
| // validate data? | |
| } | |
| } | |
| // *ViewModel represents view state | |
| class TrackListViewModel { | |
| tracks = observable.array<TrackModel>() // rendered by UI |
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 definitions for vanilla-tilt 1.3 | |
| // Project: https://github.com/micku7zu/vanilla-tilt.js | |
| // Definitions by: Livio Brunner <https://github.com/BrunnerLivio> | |
| // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | |
| declare module "vanilla-tilt" { | |
| /** | |
| * A smooth 3D tilt javascript library forked from Tilt.js (jQuery version). | |
| */ | |
| namespace VanillaTilt { | |
| /** |
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 { action, observable } from "mobx" | |
| import { observer } from "mobx-react" | |
| import * as React from "react" | |
| export type FetcherProps<T> = { | |
| longWaitTimeout?: number | |
| fetch: () => Promise<T> | |
| render: (fetchState: FetchState<T>) => React.ReactNode | |
| } |
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 definitions for vanilla-tilt 1.3 | |
| // Project: https://github.com/micku7zu/vanilla-tilt.js | |
| // Definitions by: Livio Brunner <https://github.com/BrunnerLivio> | |
| // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | |
| /** | |
| * A smooth 3D tilt javascript library forked from Tilt.js (jQuery version). | |
| */ | |
| declare namespace VanillaTilt { | |
| /** |
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' | |
| const timelineEvents = [ | |
| { | |
| date: 'January', | |
| note: 'Words words words', | |
| }, | |
| { | |
| date: 'March', | |
| note: 'Scaling open maps for Jakarta flooding — and printed maps', |
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 } from 'react'; | |
| import Aux from './hoc/Aux'; | |
| import './App.css'; | |
| import First from './Container/First'; | |
| class App extends Component { | |
| constructor() | |
| { | |
| super(); | |
| this.state={ |
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' | |
| class ScriptLoader extends React.Component { | |
| state = { | |
| loaded: false | |
| } | |
| componentDidMount() { | |
| const script = document.createElement('script') | |