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
| // Gekke type-shit in Typescript | |
| // duck typing | |
| // interface IFoo { | |
| // toString: () => string | |
| // } | |
| type ToStringable = { myToString: () => string } | |
| function loggo<T extends ToStringable>(x: T) { |
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
| "editor.tokenColorCustomizations": { | |
| "textMateRules": [ | |
| { | |
| "name": "Comment", | |
| "scope": [ | |
| "comment", | |
| "punctuation.definition.comment" | |
| ], | |
| "settings": { | |
| "fontStyle": "italic", |
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 validOption = (options, key) => options && options[key] && typeof options[key] === 'function' | |
| const formatOptions = options => { | |
| let result = { } | |
| result.mapPayload = validOption(options, 'handleError') ? options.mapPayload : (context, payload) => payload | |
| result.formatUrl = validOption(options, 'formatUrl') ? options.formatUrl : (context, payload, url) => url | |
| result.handleResponse = validOption(options, 'handleResponse') ? options.handleResponse : _ => _ | |
| result.handleError = validOption(options, 'handleError') ? options.handleError : _ => _ | |
| return result | |
| } |
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
| setupApiCall( | |
| customerModule, | |
| 'fetchCustomer', | |
| fetchCustomerUrl, | |
| axios.get, | |
| { | |
| formatUrl: (url, payload) => (fetchCustomerUrl + '?ID=' + payload.customerId), | |
| handleResponse: (context, response) => { context.commit('setCustomer', response.data) } | |
| } | |
| ) |
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 customerModule = { | |
| state: { customer: undefined }, | |
| getters: { | |
| customer(state) { return state.customer } | |
| }, | |
| mutations: { | |
| setCustomer(state, customer) { state.customer = customer } | |
| }, | |
| actions: {} | |
| } |
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 fetchCustomer(context, payload) { | |
| context.commit('setFetchCustomerPending', true) | |
| context.commit('setFetchCustomerError', undefined) | |
| const url = fetchCustomerUrl + '?ID=' + payload.customerId | |
| axios.get(url).then( | |
| (response) => { | |
| context.commit('setFetchCustomerPending', false) | |
| context.commit('setCustomer', response.data) | |
| }, | |
| (error) => { |
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 initialState = { | |
| customer: undefined, | |
| fetchCustomerPending: false, | |
| fetchCustomerError: undefined, | |
| updateCustomerPending: false, | |
| updateCustomerError: undefined, | |
| } | |
| const getters = { | |
| customer(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
| const initialState = { | |
| client: undefined, | |
| fetchClientPending: false, | |
| fetchClientError: undefined, | |
| updateClientPending: false, | |
| updateClientError: undefined, | |
| } | |
| const getters = { | |
| client(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 { Type, Component, Pipe, EventEmitter } from '@angular/core'; | |
| const ANNOTATIONS = '__annotations__'; | |
| const PARAMETERS = '__parameters__'; | |
| const PROP_METADATA = '__prop__metadata__'; | |
| export type Mocked<T> = { [P in keyof T]: T[P] }; | |
| type Constructor<T> = Function & { prototype: T }; | |
| export function mockType<T>(type: Constructor<T>, overrides: Partial<T> = {}): Constructor<Mocked<T>> { |
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
| /* | |
| This program outputs: | |
| Bonjour 5 | |
| Hello 5 | |
| Bonjour 7 | |
| Bonjour 11 | |
| Hello 11 | |
| */ |
NewerOlder