Skip to content

Instantly share code, notes, and snippets.

View core.js
// The core app code
var myApp = (function () {
'use strict';
// Create a public methods object
var methods = {};
/**
* Extend the public methods object
@pwFoo
pwFoo / broadcast-channel-es6.js
Created Nov 7, 2021 — forked from alexis89x/broadcast-channel-es6.js
Broadcast Channel API polyfill
View broadcast-channel-es6.js
/**
@class BroadcastChannel
A simple BroadcastChannel polyfill that works with all major browsers.
Please refer to the official MDN documentation of the Broadcast Channel API.
@see <a href="https://developer.mozilla.org/en-US/docs/Web/API/Broadcast_Channel_API">Broadcast Channel API on MDN</a>
@author Alessandro Piana
@version 0.0.6
*/
/*
@pwFoo
pwFoo / sw.js
Created Jul 25, 2021 — forked from felquis/sw.js
sw.js
View sw.js
/*
Copyright 2014 Google Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
@pwFoo
pwFoo / PubSub.js
Created Jul 24, 2021 — forked from kjantzer/PubSub.js
PubSub.js - Simple Publish/Subscribe "Class"
View PubSub.js
/*
Lightweight PUBLISH / SUBSCRIBE Class
Original code from: <http://blog.bobcravens.com/2011/01/loosely-coupled-javascript-using-pubsub/>
Can be initialized on other Objects to provide pub/sub functionality within that object
ex: this.events = new PubSub();
*/
@pwFoo
pwFoo / pubsub.js
Created Jul 24, 2021 — forked from learncodeacademy/pubsub.js
Basic Javascript PubSub Pattern
View pubsub.js
//events - a super-basic Javascript (publish subscribe) pattern
var events = {
events: {},
on: function (eventName, fn) {
this.events[eventName] = this.events[eventName] || [];
this.events[eventName].push(fn);
},
off: function(eventName, fn) {
if (this.events[eventName]) {
View hooks-in-a-nutshell.js
// WARNING: There's much more to know/do around hooks, and
// this is just a simplification of how these work.
// shared references, updated
// per each hook invoke
let execution = null;
let current = null;
let context = null;
let args = null;
@pwFoo
pwFoo / hook.js
Created Jun 29, 2021 — forked from MaherSaif/hook.js
simple javascript hooks system
View hook.js
Expected Result:
----------------
One
Two
Three
Four
Six
@pwFoo
pwFoo / index.html
Created Jun 27, 2021
jQ - Minimal jQuery like framework with event delegation, minimal router and mapping Nodelist items to Node features
View index.html
<!DOCTYPE html>
<html lang="de">
<head>
<script src="jQ.js"></script>
<script type="text/javascript">
// create a global instance of jQ
const $ = new jQ()
// Click Event (event delegation, would work with later added elements too!)
$('a[href="/test"]').on('click', (e) => { $('.test').innerHTML = "Clicked!"; e.preventDefault() })
@pwFoo
pwFoo / README.md
Created May 15, 2021 — forked from joyrexus/README.md
Vanilla JS equivalents of jQuery methods
View README.md

Sans jQuery

Events

// jQuery
$(document).ready(function() {
  // code
})
@pwFoo
pwFoo / the-bind-problem.jsx
Created Apr 17, 2021 — forked from Restuta/the-bind-problem.jsx
React, removeEventListener and bind(this) gotcha
View the-bind-problem.jsx
/* Sometimes it's pretty easy to run ito troubles with React ES6 components.
Consider the following code: */
class EventStub extends Component {
componentDidMount() {
window.addEventListener('resize', this.onResize.bind(this)); //notice .bind
}
componentWillUnmount() {
window.removeEventListener('resize', this.onResize.bind(this));