Skip to content

Instantly share code, notes, and snippets.

@matthewp
matthewp / handler.js
Last active October 18, 2018 11:56
Testing with generator functions
const action = (name, ...args) => {
return [name, args];
};
const GET_TODOS = Symbol.for('action.getTodos');
const getTodos = action.bind(null, GET_TODOS);
function* route() {
let todos = yield getTodos();
@matthewp
matthewp / for-in.js
Created September 11, 2018 17:38
For in loops
let grandparent = Object.create(Object.prototype, {
foo: {
enumerable: true,
configurable: true,
writable: true,
value: "1"
}
})
let parent = Object.create(grandparent, {
foo: {
@matthewp
matthewp / page1.html
Last active September 7, 2018 20:31
Page test
<!doctype html>
<html lang="en">
<title>Page 1</title>
<main id="main"></main>
<h1>Links</h1>
<ul>
<li><a href="/about">About</a></li>
<li><a href="/page2.html">Page 2</a></li>
@matthewp
matthewp / notes.md
Created July 24, 2018 11:01
AWS Lambda function CLI

Run the following command to create a new function:

aws lambda create-function \
--region us-west-2 \
--function-name some-app_some-fn \
--zip-file fileb://main.zip \
--role arn:aws:iam::891234447:role/something_lambda_function \
--handler main.handle \
--runtime nodejs8.10
@matthewp
matthewp / release-notes.md
Last active July 19, 2018 18:00
steal-tools notes

This is the second major release of steal-tools 2.0.0. When upgrading be sure to also get steal 2.0.0. See the migration guide and upgrade today.

Major features

Tree shaking

In steal-tools 2.0.0 unused exports (and unused modules) are tree shaken away. You don't need to do anything to get this behavior. In the chance that your code doesn't work well with tree shaking, you can disable it through a build option:

stealTools.build({}, {
@matthewp
matthewp / steal.js
Created June 26, 2018 19:31
steal.js with fix
!function(e){"object"==typeof exports?module.exports=e():"function"==typeof define&&define.amd?define(e):"undefined"!=typeof window?window.Promise=e():"undefined"!=typeof global?global.Promise=e():"undefined"!=typeof self&&(self.Promise=e())}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
/** @license MIT License (c) copyright 2010-2014 original author or authors */
/** @author Brian Cavalier */
/** @author John Hann */
/**
* ES6 global Promise shim
*/
var unhandledRejections = require('../lib/decorators/unhandledRejection');
var PromiseConstructor = unhandledRejections(
@matthewp
matthewp / index.html
Last active June 20, 2018 20:19
aws-amplify
<script src="./node_modules/steal/steal.js"></script>
@matthewp
matthewp / .gitignore
Last active May 29, 2018 15:24
class props
node_modules/
dist/
package-lock.json

can-view-nodelist removal

In May 2018 I spent a few days exploring what it would take to remove can-view-nodelist from CanJS. The attempt stems from canjs/can-observation#125

The idea is to be able to automatically teardown observations that are created within templates when an outer observation updates itself. This would prevent needing to use nodelists to teardown observations.

The code for this looks like:

var stopTrap = observation.trapBindings();
@matthewp
matthewp / main.js
Last active May 10, 2018 00:28
a pattern
const FetchTodos = Symbol();
const AnotherEffect = Symbol();
function* operationWithSideEffects() {
let todos = [];
for(let i = 0; i < 10; i++) {
let todo = yield perform(FetchTodos, i);
todos.push(todo);
}
let out = yield perform(AnotherEffect);