Skip to content

Instantly share code, notes, and snippets.

View mokargas's full-sized avatar
🏠
Working from home

Mo mokargas

🏠
Working from home
View GitHub Profile
@mokargas
mokargas / ErroryBoundaryDemo.jsx
Created April 18, 2024 23:40
Basic error boundary example
import React, { useState } from 'react';
class ErrorBoundary extends React.Component {
constructor(props) {
super(props)
this.state = { error: false }
}
static getDerivedStateFromError(error) {
return { hasError: true }
@mokargas
mokargas / MouseTrackerDemo.jsx
Created April 18, 2024 22:11
Render props example
import React, {useState, useEffect} from 'react';
const MouseTracker = ({render}) =>{
const [position, setPosition] = useState({x:0, y:0});
useEffect(()=>{
const updatePosition = (e) =>{
setPosition({
x: e.clientX,
@mokargas
mokargas / area-light.js
Last active September 5, 2017 02:25
A-Frame + Three.JS RectAreaLight
//This is now outdated. Please see: https://github.com/mokargas/aframe-area-light-component
/**
* A-Frame Wrapper for THREE.JS RectAreaLight
* @author Mo Kargas (DEVLAD) mo@devlad.com
*/
/* global AFRAME */
@mokargas
mokargas / aframe_react_anim.jsx
Last active August 31, 2017 21:54
AFrame + React + Anim
AFRAME.registerComponent('infocard', {
init: function(){
const infocard = this.el
//Find "show" elements
const shows = infocard.querySelectorAll('*[begin="show"]')
const hides = infocard.querySelectorAll('*[begin="hide"]')
infocard.addEventListener('hover', function (event) {
@mokargas
mokargas / rxjs-notes.md
Last active March 14, 2017 03:30
Rx.js Notes

Hot takes:

  • Consider 'RxJS' as being Lodash for events
  • Combines the Observer Pattern with the Iterator pattern and functional programming with collections to fill the need for an ideal way of managing sequences of events.

What is the Observer pattern

From Wikipedia: "The observer pattern is a software design pattern in which an object, called the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods."

We can mock this in JS in a pseudo-codey way

@mokargas
mokargas / react_simple.md
Last active February 28, 2017 07:53
Quick Notes on React.js Paradigms

Mostly condensing starter docs and adding other learnings. Feel free to add to or correct any misunderstandings. Shorter is better.

Lifecycle

e.g extending from React.Component

  • componentWillUnmount - Fired when a component's DOM is removed
  • componentDidMount - Fired when added to the primary DOM for the first time

State

  • State is a special property for storage on a class (this.state)
@mokargas
mokargas / npm.md
Last active February 21, 2017 09:16
Update NPM, Windows 10 x64

Source: http://stackoverflow.com/a/31520672

In short:

First, run PowerShell as Administrator

  • Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
  • npm install -g npm-windows-upgrade
  • npm-windows-upgrade
@mokargas
mokargas / HoF.md
Last active February 22, 2017 00:52
What are Higher Order Functions? (JS)

Simple definitions for HoF's:

Major Concepts:

  • A function that will take at least one function as an argument (Primary concept)
  • Does not mutate any state
  • Can return a function (?? Wikipedia)

Examples:

@mokargas
mokargas / FRP.md
Last active February 22, 2017 00:50
Simple Explanations: What is Functional Reactive Programming (FRP)?

WIP: Still searching for a simple explanation for all levels of developer (and non-devs as well)

Feel free to chime in with corrections, ideas, helpful comments.

Beats:##

  • Ideally, we want no side effects in FRP
  • Observer patterns. Subscription concept
  • Declarative in nature rather than imperative. (Ref: Definition of imperative/declarative)
  • Time varying functions, not mutable state
@mokargas
mokargas / const.js
Last active February 20, 2017 21:08
Your const isn't constant
//Const doesn't currently confer immutability, it gives immutable binding: https://mathiasbynens.be/notes/es6-const
//Will work how you expect
const baz = 42
baz = 10
//Won't work how you expect
const foo = { bar: 1 }
foo.bar = 2