Skip to content

Instantly share code, notes, and snippets.

// 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 November 7, 2021 21:41 — forked from alexis89x/broadcast-channel-es6.js
Broadcast Channel API polyfill
/**
@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 July 25, 2021 13:53 — forked from felquis/sw.js
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 July 24, 2021 12:15 — forked from kjantzer/PubSub.js
PubSub.js - Simple Publish/Subscribe "Class"
/*
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 July 24, 2021 12:15 — forked from learncodeacademy/pubsub.js
Basic Javascript PubSub Pattern
//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]) {
// 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 June 29, 2021 20:01 — forked from MaherSaif/hook.js
simple javascript hooks system
Expected Result:
----------------
One
Two
Three
Four
Six
@pwFoo
pwFoo / README.md
Created May 15, 2021 21:33 — forked from joyrexus/README.md
Vanilla JS equivalents of jQuery methods

Sans jQuery

Events

// jQuery
$(document).ready(function() {
  // code
})
@pwFoo
pwFoo / the-bind-problem.jsx
Created April 17, 2021 20:29 — forked from Restuta/the-bind-problem.jsx
React, removeEventListener and bind(this) gotcha
/* 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));
@pwFoo
pwFoo / dom-property-watcher.js
Created April 13, 2021 10:12 — forked from ebidel/dom-property-watcher.js
DOM property watcher using ES6 proxies.
// Watch accesses/sets on a DOM element property.
function watchPropsOn(el) {
return new Proxy(el, {
get(target, propKey, receiver) {
//return Reflect.get(target, propKey, receiver);
console.log('get', propKey);
return el[propKey];
},
set(target, propKey, value, receiver) {
console.log('set', propKey, value);