Skip to content

Instantly share code, notes, and snippets.

View AjayPoshak's full-sized avatar

Ajay Poshak AjayPoshak

View GitHub Profile
@marvinhagemeister
marvinhagemeister / little-vdom-decompiled.js
Created March 8, 2020 14:13
Jason little-vdom decompiled
/* eslint-disable no-unused-vars */
/* eslint-disable no-else-return */
// JSX constructor, similar to createElement()
export const h = (type, props, ...children) => {
return {
type,
// Props will be an object for components and DOM nodes, but a string for
// text nodes
props,
@sebmarkbage
sebmarkbage / WhyReact.md
Created September 4, 2019 20:33
Why is React doing this?

I heard some points of criticism to how React deals with reactivity and it's focus on "purity". It's interesting because there are really two approaches evolving. There's a mutable + change tracking approach and there's an immutability + referential equality testing approach. It's difficult to mix and match them when you build new features on top. So that's why React has been pushing a bit harder on immutability lately to be able to build on top of it. Both have various tradeoffs but others are doing good research in other areas, so we've decided to focus on this direction and see where it leads us.

I did want to address a few points that I didn't see get enough consideration around the tradeoffs. So here's a small brain dump.

"Compiled output results in smaller apps" - E.g. Svelte apps start smaller but the compiler output is 3-4x larger per component than the equivalent VDOM approach. This is mostly due to the code that is usually shared in the VDOM "VM" needs to be inlined into each component. The tr

@saqueib
saqueib / errorHandler.js
Last active June 9, 2022 06:42
Global error handling using axios interceptor for http calls http://www.qcode.in/api-error-handling-in-vue-with-axios
import axios from 'axios'
import toast from './toast'
function errorResponseHandler(error) {
// check for errorHandle config
if( error.config.hasOwnProperty('errorHandle') && error.config.errorHandle === false ) {
return Promise.reject(error);
}
// if has response show the error
@zcaceres
zcaceres / Revealing-Module-Pattern.md
Last active April 23, 2024 22:02
Using the Revealing Module Pattern in Javascript

The Revealing Module Pattern in Javascript

Zach Caceres

Javascript does not have the typical 'private' and 'public' specifiers of more traditional object oriented languages like C# or Java. However, you can achieve the same effect through the clever application of Javascript's function-level scoping. The Revealing Module pattern is a design pattern for Javascript applications that elegantly solves this problem.

The central principle of the Revealing Module pattern is that all functionality and variables should be hidden unless deliberately exposed.

Let's imagine we have a music application where a musicPlayer.js file handles much of our user's experience. We need to access some methods, but shouldn't be able to mess with other methods or variables.

Using Function Scope to Create Public and Private Methods

@tanmaypatel
tanmaypatel / isDocumentLoaded.js
Created February 16, 2014 07:39
How to check if an HTML page is already loaded. Even after "load" event has dispatched!
/* This has been supported in IE and webkit for a long time. It was added to Firefox in 3.6. Here's the spec (http://www.w3.org/TR/html5/dom.html#dom-document-readystate). "loaded" is for older Safari browsers.*/
if (document.readyState == "complete" || document.readyState == "loaded")
{
// document is already ready to go
}
/* If you want to know when the page has been parsed, but all subresources have not yet been loaded, you can add the "interactive" value: */
if (document.readyState == "complete"
|| document.readyState == "loaded"
|| document.readyState == "interactive") {
@nathansmith
nathansmith / scroll-offset.js
Last active November 27, 2023 04:51
Check if the user is scrolled to the bottom of the page.
window.onscroll = function() {
var d = document.documentElement;
var offset = d.scrollTop + window.innerHeight;
var height = d.offsetHeight;
console.log('offset = ' + offset);
console.log('height = ' + height);
if (offset >= height) {
console.log('At the bottom');