Skip to content

Instantly share code, notes, and snippets.

@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;
@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 / README.md
Last active February 18, 2018 06:32
Enyo Inspector Bookmarklet to inspect an Enyo instance by shift-clicking it.
@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;
// 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 / installer.sh
Created May 1, 2013 16:43
Parse Cloud Code installer for c9.io
#!/bin/bash
TMP_FILE=~/parse.tmp
if [ -e $TMP_FILE ]; then
echo "Cleaning up from previous install failure"
rm -f $TMP_FILE
fi
echo "Fetching latest version ..."
/**
_enyo.FittableLayout_ provides the base positioning and boundary logic for
the fittable layout strategy. The fittable layout strategy is based on
laying out items in either a set of rows or a set of columns, with most of
the items having natural size, but one item expanding to fill the remaining
space. The item that expands is labeled with the attribute _fit: true_.
The subkinds <a href="#enyo.FittableColumnsLayout">enyo.FittableColumnsLayout</a>
and <a href="#enyo.FittableRowsLayout">enyo.FittableRowsLayout</a> (or
<i>their</i> subkinds) are used for layout rather than _enyo.FittableLayout_