Skip to content

Instantly share code, notes, and snippets.

View r3dm1ke's full-sized avatar
🎯
Before software can be reusable it first has to be usable.

Michael Krasnov r3dm1ke

🎯
Before software can be reusable it first has to be usable.
View GitHub Profile
Symbol() == Symbol()
// False
Symbol('abacaba') == Symbol('abacaba')
// False
// But
const s = Symbol('sym');
s == s
// True
@r3dm1ke
r3dm1ke / data.js
Created January 13, 2020 17:07
Primitive vs complex data structures
// string is a primitive data type
const name = 'Michael';
name.toUpperCase();
// toUpperCase is not a method; it does not mutate
// the original variable
console.log(name); // Michael
// instead, it returns a new one
const NAME = name.toUpperCase();
console.log(NAME); // MICHAEL
@r3dm1ke
r3dm1ke / Car.js
Created January 12, 2020 17:23
Car class in ES6
class Car {
constructor(make, model) {
this.make = make;
this.model = model;
}
start() {
console.log('vroom');
}
@r3dm1ke
r3dm1ke / functions-are-objects.js
Created January 12, 2020 17:15
Functions are objects in JS
function iAmAnObject() {}
console.log(iAmAnObject.name); // iAmAnObject
console.log(Object.keys(iAmAnObject)); // Array []
@r3dm1ke
r3dm1ke / Car.js
Created January 10, 2020 16:12
Car class in ES5
// "class" declaration
function Car(make, model) {
this.make = make;
this.model = model;
}
// the start method
Car.prototype.start = function() {
console.log('vroom');
}
@r3dm1ke
r3dm1ke / .StateViewer.js
Last active January 9, 2020 16:48
View redux form state
import React from 'react';
import { View, TextInput, StyleSheet } from 'react-native';
import {useSelector} from 'react-redux';
const StateViewer = (props) => {
const formState = useSelector((state) => state.form);
// Prettify the JSON code:
const prettyFormState = JSON.stringify(formState, null, 2);
return (
<View style={styles.root}>
@r3dm1ke
r3dm1ke / App.js
Created January 8, 2020 15:49
Connecting Redux store to App
import React from 'react';
import { Provider } from 'react-redux';
import store from './store';
import Form from './Form';
export default function App() {
return (
<Provider store={store}>
<Form />
</Provider>
@r3dm1ke
r3dm1ke / Form.js
Last active January 8, 2020 15:49
Form component, connected to Redux Form
import React from 'react';
import { View, Button, TextInput, StyleSheet } from 'react-native';
import { Field, reduxForm } from 'redux-form';
const Form = (props) => {
const { handleSubmit } = props;
const onSubmit = (values) => console.log(values);
@r3dm1ke
r3dm1ke / App.js
Created January 8, 2020 15:27
Form component to showcase the power of Redux Form
import React from 'react';
import Form from './Form';
export default function App() {
return (
<Form />
);
}
@r3dm1ke
r3dm1ke / store.js
Created January 8, 2020 15:17
Store for Redux Form Tutorial
import {combineReducers, createStore} from 'redux';
import {reducer as formReducer} from 'redux-form';
const rootReducer = combineReducers({
// ... the rest of your reducers
form: formReducer
});
const store = createStore(rootReducer);