Skip to content

Instantly share code, notes, and snippets.

View helpers.js
module.exports.addDefaultImport = function addImport(tree, mod, name) {
tree.children.unshift({
type: 'import',
value: `import _${name} from '${mod}'`,
});
return `_${name}`;
};
View use-debounce.js
function useDebounced(value, timeout) {
let [debouncedValue, setDebouncedValue] = useState(value)
useEffect(() => {
let timeoutId = setTimeout(() => {
setDebouncedValue(value)
}, timeout)
return () => {
clearTimeout(timeoutId)
@ryanto
ryanto / use-depends-on.js
Created May 11, 2020
Depends on. Think of it like a useEffect where you unapologetically use the dependencies list to control when the effect should run.
View use-depends-on.js
import { usePrevious } from "./use-previous";
import { useRef, useEffect } from "react";
export const useDependsOn = (
value,
functionToRun,
{ initial = true } = {}
) => {
let serialized = JSON.stringify(value);
let previous = usePrevious(serialized);
View controllers.application.js
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
View controllers.application.js
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
actions: {
update(key, value) {
console.log(`updating ${key} to ${value}`);
this.model.set(`variables.${key}`, value);
}
View controllers.application.js
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
@ryanto
ryanto / fullscreen.js
Created May 22, 2018
Fullscreen test helper
View fullscreen.js
// tests/helpers/fullscreen.js
import $ from 'jquery';
import { registerAsyncHelper } from '@ember/test';
export default registerAsyncHelper('fullscreen', function() {
window.QUnit.config.testTimeout = 9999999;
$('#ember-testing-container').css({
background: 'initial',
View components.my-component.js
import Ember from 'ember';
export default Ember.Component.extend({
store: Ember.inject.service(),
didInsertElement() {
let store = this.get('store');
let model = store.createRecord('my-model');
this.set('model', model);
View controllers.application.js
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'x'
});
View worker-killer.md