Skip to content

Instantly share code, notes, and snippets.

@rjgotten
rjgotten / application-code.js
Last active May 18, 2020 13:44
Using a Webpack InjectOptionsPlugin to supply centralized loader configuration to loaders that are added with inline loader!module import syntax
import Worker from "workerize-loader!./worker"
var loaderUtils = require("loader-utils");
var parse = require("can-stache-ast").parse;
function makeRenderer(imports, intermediate, filename) {
intermediate = JSON.stringify(intermediate);
filename = JSON.stringify(filename);
imports = imports.map(function(imported) {
imported = JSON.stringify(imported);
return `${imported} : Promise.resolve(require(${imported}))`
@rjgotten
rjgotten / import.js
Created August 23, 2016 12:29
More complete AMD loader support for can-util/js/import/import
var isFunction = require('../is-function/is-function');
var global = require("../global/global")();
/**
* @module {function} can-util/js/import/import import
* @parent can-util/js
* @signature `importModule(moduleName, parentName)`
*
* ```js
* var importModule = require("can-util/js/import/import");
@rjgotten
rjgotten / literal.js
Last active August 29, 2015 14:20
Emit literal content with Less plugin functions and detached rulesets
function Literal( text ) {
this.text = text;
}
Literal.prototype = new tree.Node();
Literal.prototype.constructor = Literal;
Literal.prototype.type = "Literal";
Literal.prototype.accept = function ( visitor ) {};
Literal.prototype.eval = function ( context ) {
return new Literal( this.text );
.each(@list, @ruleset) {
@plugin "plugins/lambda";
@length : length(@list);
._iterate(1);
._iterate(@index) when (@index =< @length) {
@item : extract(@list, @index);
@lambda : lambda(@item, @index, item index, @ruleset);
@lambda();
@rjgotten
rjgotten / foreach.less
Last active August 29, 2015 14:15
Using detached rulesets as lambda delegates without scoping issues; in reply to: https://gist.github.com/seven-phases-max/5280eacdf3d591f35163
// @mixin
// Loops over all items in the specified list and for each item executes
// a special `.\\` mixin declared by the specified ruleset. The ruleset
// and mixin combination is used to emulate a lambda function delegate.
// @param {List} list
// The list over which to loop.
// @param {Ruleset} lambda
// A ruleset that may define the `.\\` mixin that is used to process the
// individual list items. The mixin should correspond to the
// following signature:
@rjgotten
rjgotten / can.compute.when.js
Last active August 29, 2015 14:06
Wrapping can.Deferred as a can.compute
can.compute.when = function( computer ) {
var
promise,
combined,
result;
// Ensure that we always get back a then-able promise from `computer`,
// and that it is infact a `can.compute` and not a regular function.
promise = can.compute( function() { return can.when( computer()) });