Skip to content

Instantly share code, notes, and snippets.

Domenic Denicola domenic

Block or report user

Report or block domenic

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@domenic
domenic / di-in-requirejs.js
Created Oct 10, 2011
Dependency injection sample with RequireJS
View di-in-requirejs.js
// EntryPoint.js
define(function () {
return function EntryPoint(model1, model2) {
// stuff
};
});
// Model1.js
define(function () {
return function Model1() {
@domenic
domenic / di-plus-sl-modules.js
Last active Sep 27, 2015
Intermediate DI/service locator solution for JavaScript modules
View di-plus-sl-modules.js
//////////////////////////
// Pure "DI style" modules
// BackEndAnalytics.js
define(function () {
return function BackEndAnalytics() {
this.send = function () { };
};
});
@domenic
domenic / promise-assertions.js
Created Nov 10, 2011
Sample of upcoming promise assertions module
View promise-assertions.js
// Say that doSomethingAsync returns a promise, and expected is the value we want it to return.
// With my library you can do the following
test("doSomethingAsync() returns expected", function () {
equal(doSomethingAsync(), expected, "As expected");
});
// Normally you would have to do
test("doSomethingAsync() returns expected", function () {
QUnit.stop();
@domenic
domenic / gist:1370488
Created Nov 16, 2011
Discussion of AMD vs. CommonJS Modules/2.0
View gist:1370488

Just want to chime in that I'm glad people are still interested in CommonJS Modules/2.0. We have a working implementation that hopefully will be of interest, and have factored out the generally applicable parts of our test suite. Also see the announcement thread on the CommonJS list.

That said, personally I've been a bit disappointed with the CommonJS community's lack of enthusiasm on Modules/2.0. We picked it up early in our project lifecycle, and ran with it full speed. At the time it seemed like a more standardized alternative to AMD.

However, over time it's become clear that AMD has not only won mindshare but also has a much more active group of maintainers and a better, more egalitarian standards process. Whereas, Modules/2.0 has only the perennially busy Wes Garland, leaving a self-hosted PDF s

@domenic
domenic / user.dic
Created Nov 18, 2011
Math and science words that need to be in dictionaries but usually aren't
View user.dic
BPS
CKM
CMB
CSS
CVS
KMS
LHC
LQG
LSZ
NSF
View cancellable-deferreds.js
var deferredsByPromise = new WeakMap();
recordRetriever.retrieveAsync = function (query) {
var deferred = Q.defer();
server.doPagedRetrieveWithCallback(query, 0, function (err, result) {
// wire up deferred.resolve and deferred.reject.
// recurse appropriately, increasing pagination,
// UNLESS deferred.isCancelled.
});
View cancellable-promises.js
recordRetriever.retrieveAsync = function (query) {
var deferred = Q.defer();
server.doPagedRetrieveWithCallback(query, 0, function (err, result) {
// wire up deferred.resolve and deferred.reject.
// recurse appropriately, increasing pagination,
// UNLESS deferred.isCancelled.
});
deferred.promise.cancel = deferred.cancel;
@domenic
domenic / README.md
Last active Apr 6, 2018
Using promises in a UI context
View README.md

The scenario:

  • We are writing a digital textbook-reading app.
  • Most of the time you have a "basic" license for your textbook, but one (and only one) of your computers can request an "enhanced" license.
  • You can only print from the computer with the enhanced license.

The problem statement:

View q-bind.js
// From discussion at https://groups.google.com/d/msg/q-continuum/68ro20aB358/7kUCAF19qqAJ
// Naive version
function fAsync(a, b) {
if (a) {
return Q.reject(new Error());
}
if (b) {
return Q.resolve(42);
}
@domenic
domenic / knockout-es5.js
Created Feb 10, 2012
Speculations on an ES5-style KnockoutJS
View knockout-es5.js
// DESIRED (pending bikeshedding):
// Create using special factory function. Will automatically create `ko.observable`s, `ko.observableArray`s, and
// `ko.computed`s for you, but hide them behind getters/setters.
var viewModel = es5ViewModel({
firstName: "Luke",
lastName: "Skywalker",
fullName: function () {
return this.fullName + this.lastName;
},
You can’t perform that action at this time.