Skip to content

Instantly share code, notes, and snippets.

@polotek
polotek / gist:9985338
Created April 4, 2014 23:52
Single page apps and "fast switching"
"broad question: how does fast load work? site is a one page app, switches categories similarly, but no URL relation."
https://twitter.com/drewdil/status/452228299150721024

Today I had a brief debate on twitter about AMD vs CommonJS, https://twitter.com/TechWraith/status/441387541778808832. It's a debate worth having for sure. But I had to bail out of this one. The thing that annoyed me is that the first argument that people bring up to disquality AMD is "the syntax is too complex". I disagree with this. There are lots of reasons to prefer CommonJS over AMD, but the module authoring syntax is not a very good one. There was also a related statement that AMD authoring introduces more "cognitive overhead". This is absolutely true. But I don't consider this to be synonymous with "complexity" by any means.

So I thought I'd explore some comparable examples. Here's a simple one that was offered up by someone else in the thread. This was on twitter so I can forgive erring on the side of brevity.

AMD

define('myThing', ['some', 'deps'], function (some, deps) {
  //my code
  
 return myThing;
@polotek
polotek / proposal.md
Last active January 2, 2016 21:29
My talk proposal for JSConf US 2014 or anyone else who wants to hear it.

We're all building a client-side framework. And they're all different implementations of the same stuff. A while back I tweeted this. https://twitter.com/polotek/status/339852946508505089

"When it comes down to it, everybody is building variants of the same MVCish framework. We should be talking about the shared patterns."

I want to explore the shared patterns that we all use to build our front-end apps. Patterns like the following.

  • Representing a list of data items. Updating the view when the list updates.
  • Rendering nested views.
  • Data binding, e.g. automatic UI updates
  • Controlling when and how the UI gets re-rendered on data updates
@polotek
polotek / binding_attribute_pattern.js
Created December 20, 2013 00:30
Messing around with a pattern to update classes on a Backbone.Component.
var $body = $('body')
, stateMap = { ON: 'On :)', OFF: 'Off :(', BLINK: 'Blinking!' }
, TriStateSwitch = Backbone.Component.extend({
tagName: 'button',
events: {
'click': 'updateState'
},
attrBindings: {
'alt': 'state'
}
@polotek
polotek / gist:7954294
Last active December 31, 2015 07:29
A list of potential blog topics I've had on my list for a while.

A list of potential blog topics I've had on my list for a while.

  1. Merging 2 technology stacks - About difficulties in what it means to make the Yammer product part of Microsoft Office from a technical perspective.
  2. What does "offline web app" mean? - Some musings on the rising movement to promote offline first support. I put this down before the offline first stuff the Hoodie folks have been talking about. Intrigued so far.
  3. "From engineer to engineering manager" - Introspective post after accepting the fact that I'm not really an engineer these days.
  4. How we hire at Yammer - Been promising some folks this.
  5. "Gut feeling" considered harmful. - This topic has been burning a hole in my brain lately.
@polotek
polotek / event_emitter_example.js
Last active December 17, 2015 22:59
Simple example of a node event emitter
// Grab the EventEmitter constructor. events is a core node module.
var Emitter = require('events').EventEmitter;
// Our internal function will generate random numbers
function randomInt(limit) {
return Math.ceil( Math.random() * limit );
}
module.exports = function(limit) {
if(!(limit && limit > 0)) {
var App = Ember.Application.create();
App.Store = DS.Store.extend({
revision: 11
, adapter: YamAdapter.create()
});
App.YamModel = DS.Model.extend({
type: DS.attr('string')
, url: DS.attr('string')
, webUrl: DS.attr('string')
});
// First version of parent
var Parent = Backbone.View.extend({
events: {
click: "handleClick"
, focus: "onFocus"
}
});
// Updated parent to support extension of "events"
// First version of parent
@polotek
polotek / ember_hurdles.md
Last active March 30, 2017 05:37
Hurdles getting started with Ember.js

This is a brain dump of my experience trying to get something going with Ember.js. My goal was to get to know the ins and outs of the framework by completing a pretty well defined task that I had lots of domain knowledge about. In this case reproducing a simple Yammer feed. As of this time, I have not been able to complete that task. So this is a subjective rundown of the things I think make it difficult to get a handle on Ember. NOTE: My comments are addressing the Ember team and giving suggestions on what they could do to improve the situation.

App setup

The new guides have pretty good explanation of the various parts of the framework; routers, models, templates, views. But it's not clear how they all get strapped together to make something that works. There are snippets of examples all over the place like:

App.Router.map(function() {
  match('/home').to('home');
});
<!-- template_file.html -->
<div>
  <p class="title">{title}</p>
  <span class="timestamp">{created_date}</span>
</div>
Post({