Skip to content

Instantly share code, notes, and snippets.

@thomaswrenn
thomaswrenn / index.html
Created January 12, 2021 22:31
Tic Tac Toe
<div id="errors" style="
background: #c00;
color: #fff;
display: none;
margin: -20px -20px 20px;
padding: 20px;
white-space: pre-wrap;
"></div>
<div id="root"></div>
<script>
@thomaswrenn
thomaswrenn / index.html
Created December 10, 2020 23:06
Tic Tac Toe
<div id="errors" style="
background: #c00;
color: #fff;
display: none;
margin: -20px -20px 20px;
padding: 20px;
white-space: pre-wrap;
"></div>
<div id="root"></div>
<script>
@thomaswrenn
thomaswrenn / controllers.application\.js
Last active November 10, 2020 07:09
Sorting Lodash vs Ember.computed.sort
import { sort } from '@ember/object/computed';
import { computed, get } from '@ember/object';
import { compare } from '@ember/utils';
import Controller from '@ember/controller';
import { sortBy } from 'lodash';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
test: Ember.computed(function() { return ['car', 'test']; }),
firstObject: Ember.computed.reads('test.firstObject'),
test2: Ember.computed(function() { return []; }),
@thomaswrenn
thomaswrenn / controllers.application.js
Last active September 30, 2018 23:00
Asynchronously Fetched Default Param Value Ember 2.12
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
html {
color: #222;
font-size: 1em;
line-height: 1.4;
}
.video-share {
width: 100%;
text-align: center;
margin-top: 30px;
import Ember from 'ember';
export default Ember.Component.extend({
classNames: ["TableGridCell"]
});

Doesn't trigger the computed on page load or update (tested in a controller):

const { computed, get, inject } = Ember;
import { getFeatureFlags } from 'vishnu/sagas/selectors';

export default Ember.Component.extend({
  reduxStore: inject.service('saga-store'),
  featureFlags: computed('reduxStore.state', function() {
    return getFeatureFlags(get(this, 'reduxStore.state'));
 }),
function _pasteText($element, text, { availableFormats }) {
  const pasteEvent = new window.Event('paste');
  pasteEvent.clipboardData = {
    getData: type => (type in availableFormats) ? text || '' : ''
  };
  placeCursorAtStartOfNode($element[0]);
  $element[0].dispatchEvent(pasteEvent);
  $element.closest('.AsMediumEditor').trigger(Ember.$.Event('input'));
}

controller.hbs:

<div class="pad-xs-30b">
  {{thing-collection
    title=title
    things=things

    doAwesomeThingToThing=(action "doAwesomeThingToThing")
  }}
</div>