Skip to content

Instantly share code, notes, and snippets.

View marcelmokos's full-sized avatar

Marcel Mokoš marcelmokos

View GitHub Profile
@marcelmokos
marcelmokos / typed-object-argument-function.ts
Created October 16, 2019 20:55
typed object argument function
const fullName = (
{firstName = "", lastName = ""} // we are providing default values
: {firstName: string, lastName: string} // type, can be inferenced
= {} // default value object for object argument
) => `${firstName} ${lastName}`;
@marcelmokos
marcelmokos / functions.ts
Created October 16, 2019 19:51
typing typescript functions
function add(a: number, b: number): number { return a + b };
const add = (a: number, b: number): number => a + b;
type Arithmetics = (a: number, b: number) => number;
// or
/*
interface Arithmetics {
(a: number, b: number): number;
}
@marcelmokos
marcelmokos / jsdoc.js
Created October 16, 2019 15:12
jsdoc example
/**
* A person object with name, age and sayName method.
* @typedef {Object} Person
* @property {string} name The person's name.
* @property {number} age The person's age.
* @property {Function} sayName A function that alerts the person's name.
*/
const person = {
name: 'Joe',
age: 32,
import React from "react";
import {inject, observer} from "mobx-react";
export class SubjectsPresenter extends React.Component {...}
export default inject(
({subjectStore, translator}, {subjectSelections, ...props}) => {
const subjectOptions = subjectStore.getFilteredSubjects(subjectSelections);
return {
subjectOptions,
// see types of prompts:
// https://github.com/enquirer/enquirer/tree/master/examples
//
module.exports = [
{
type: "input",
name: "name",
message: "What's the name of your package?"
},
{
@marcelmokos
marcelmokos / Calendar.defaultProps.js
Last active January 19, 2019 23:20
Calendar.defaultProps
Calendar.defaultProps = {
Wrapper: styled.div`
display: flex;
flex-direction: row;
`,
Column: styled.div`
display: flex;
flex-direction: column;
margin: 0.5rem;
`,
@marcelmokos
marcelmokos / index.js
Created January 18, 2019 15:36
Calendar
import React from "react";
import ReactDOM from "react-dom";
import Calendar from "./components/Calendar";
const App = () => (
<>
<Calendar>
{({ Wrapper, Column, Box, Item, headers }) => (
<Wrapper>
{headers.map((header, index) => (
@marcelmokos
marcelmokos / Strategy in react.js
Last active January 16, 2019 14:29
Openslava
const FormattedNumber = ({ value, roundingFn = val => val }) => roundingFn(value);
//js
console.log(
FormattedNumber({value: 5.6}) /* 5.6 */
);
//jsx
<FormattedNumber value={5.6} /> /* 5.6 */
<FormattedNumber value={5.6} roundingFn={Math.floor} /> /* 5 */
@marcelmokos
marcelmokos / asyncIt.js
Last active December 22, 2018 22:00
test two elements have same classes
/*-------- Promise.then() syntax ---------*/
// when expect() is in Promise.then() method body
// we have to use callback function done()
it("test two inputs to have labels with same classes using Promise.then() ", (done) => {
getInputsLabelElement(input1).then((label1) => {
getInputsLabelElement(input2).then((label2) => {
label1.getAttribute("class").then((label1Classes) => {
label2.getAttribute("class").then((label2Classes) => {
expect(label1Classes).toBe(label2Classes);
Original Value Converted to Number Converted to String Converted to Boolean
false 0 false false
true 1 true true
0 0 0 false
1 1 1 true
0 0 0 true
000 0 000 true
1 1 1 true
NaN NaN NaN false
Infinity Infinity Infinity true