Skip to content

Instantly share code, notes, and snippets.

@ryanjduffy
ryanjduffy / useIdleMapReduce.ts
Created December 21, 2020 18:41
useIdleMapReduce
function useIdleMapReduce<T = any, M = T, R = M>(
array: T[],
map: (item: T, index: number, array: T[]) => M,
reduce: (acc: R, value: M, index: number, array: M[]) => R,
initialValue: R
) {
const ref = useRef({ array, out: [] as M[], acc: initialValue, index: 0, id: null });
const result = useCallback(() => {
if (ref.current.index !== -1) callback(true);
return ref.current.acc;
@ryanjduffy
ryanjduffy / App.js
Last active November 9, 2018 00:16
@enact/analytics
// How it might be used by an application
import configure, {fetchConfig} from './analytics';
// example of some custom logic that could be used to add metadata to the log
const getPanelName = (node) => {
const panel = node.closest('article[role="region"]');
let panelName = '<None>';
if (panel) {
const header = panel.querySelector('header h1');
@ryanjduffy
ryanjduffy / dco.md
Created July 25, 2018 16:19
Enact Developer Grant and Certificate of Origin 1.0

Enact Developer Grant and Certificate of Origin 1.0

By making a contribution to the Enact Project (“Project”), I represent and warrant that:

a) The contribution was created in whole or in part by me and I have the right to submit the contribution on my own behalf or on behalf of a third party who has authorized me to submit this contribution to the Project; or

b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right and authorization to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license) that I have

@ryanjduffy
ryanjduffy / MoreToolbar.patch
Last active March 22, 2017 15:48
MoreToolbar.patch
diff --git a/source/MoreToolbar.js b/source/MoreToolbar.js
index ab432e6..2c44e4c 100644
--- a/source/MoreToolbar.js
+++ b/source/MoreToolbar.js
@@ -51,22 +51,37 @@ enyo.kind({
this.inherited(arguments);
this.$.client.setLayoutKind(this.clientLayoutKind);
},
+ rendered: function(){
+ this.reflow();
@ryanjduffy
ryanjduffy / debugger.html.diff
Created February 26, 2017 02:07
Auto-expand breakpoints when adding a new breakpoing in debugger.html
diff --git a/src/components/SecondaryPanes/index.js b/src/components/SecondaryPanes/index.js
index 43dcb33..f4aad39 100644
--- a/src/components/SecondaryPanes/index.js
+++ b/src/components/SecondaryPanes/index.js
@@ -65,6 +65,15 @@ const SecondaryPanes = React.createClass({
displayName: "SecondaryPanes",
+ componentWillReceiveProps(nextProps) {
+ const { breakpoints: { size }} = this.props;
@ryanjduffy
ryanjduffy / logState.js
Last active January 30, 2023 08:43
Log React State Changes
import React from 'react';
const original = React.Component.prototype.setState;
const logState = function (type, current, updated) {
console.log(type.displayName || type.name || 'Component', 'updating', current, 'with', updated);
}
const logger = function (partialState, callback) {
const type = this._reactInternalInstance._currentElement.type;
// vim: syntax=JSX
import React from 'react';
export default class MyClass extends React.Component {
render() {
return (
<a href="google.com">Let's head to google.com</a>
);
}
}
@ryanjduffy
ryanjduffy / README.md
Last active August 29, 2015 14:27
Console jsperf

Usage Example

// Setup code before all tests are ran
jsperf.before(function () {
   testStr = '-1/2';
});

// Teardown code after all tests are ran
jsperf.after(function () {
@ryanjduffy
ryanjduffy / App.js
Last active August 29, 2015 14:20
GridListImageItem + Badge Overlay
require('spotlight');
var
ready = require('enyo/ready'),
kind = require('enyo/kind'),
GridListImageItem = require('moonstone/GridListImageItem'),
ImageBadge = require('moonstone/ImageBadge');
ready(function () {
var C = kind({
@ryanjduffy
ryanjduffy / codepen.html
Created June 18, 2014 16:40
CodePen.io Launcher for EnyoJS
<html>
<head>
<title>CodePen.io Launcher for EnyoJS</title>
</head>
<body>
<form id="form" action="http://codepen.io/pen/define" method="POST"><input id="data" type="hidden" name="data"></form>
<script>
var q = document.location.search.substring(1);
var libs = q.split(",");