Skip to content

Instantly share code, notes, and snippets.

View SMotaal's full-sized avatar
♾️
Making sure I'm not missing something!

Saleh Abdel Motaal SMotaal

♾️
Making sure I'm not missing something!
View GitHub Profile
@SMotaal
SMotaal / README.md
Last active March 17, 2018 13:36
Polymer 2 / TypeScript (using 2.0-preview branches)

Rational

The TypeScript 2.0-typescript branch seems to be lagging and isolated, with all components having 2.0-preview branches yet the 2.0-typescript README has not even been changed from the 2.0-preview text. Until a proper Polymer/TypeScript workflow is recommended and supported by the Polymer team, the basic idea is to maximize on the use of the essential features that TypeScript offers and not invest too much into hard-core features that require the workflow to be tightly coupled with late-bound transpilation of complex TypeScript projects (with modules / loaders). Another thing to address is how Hydrolysis fails to analyze and iron-component-page fails to document TypeScript-based components, not making good use of the elegant property declarations and decorators used in TypeScript. For now, a temporary workaround is needed to ensure that properties are defined and documented with proper types and default values, but the workaround needs to be easily replaceable once we have better Polymer/TypeScript

@SMotaal
SMotaal / README.md
Last active October 4, 2017 16:46
A simple TypeScript loader using NodeJS 9+ declarative loader API

A simple TypeScript loader using NodeJS 9+ declarative loader API

Purpose

This loader is intended to show very quickly how to use the proposed NodeJS 9.0.0 loader API to be able to compile TypeScript files on demand. It is not a stable solution in any way.

Using Node 9+ Loader

@SMotaal
SMotaal / surrogate-pairs.js
Created October 10, 2017 17:12
Surrogate Pairs Roundtrip
(
(
str,
c = `${str}`.codePointAt(0),
p = 0x10000, q = 0x400, r = 0xD800, s = 0xDC00,
h = ~~((c-p) / q) + r, l = (c - p) % q + s
) => ({
h, l,
c1: c, c2: (h - r) * q + l - s + p
})
@SMotaal
SMotaal / README.md
Created October 20, 2017 12:21
M?JS Pattern

This gist shows a living realworld example of how a complex NodeJS single-file module can be written in both JS and MJS with the bulk of the files being identical and imports and exports hoisted together. This is done to promote consistency by reducing the task of code updates to a simple copy/paste between the files if transpilaing is not possible.

@SMotaal
SMotaal / markdown.css
Created November 1, 2017 23:31
GitHub Markup
.markdown-body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
font-size: 16px;
line-height: 1.5;
word-wrap: break-word
}
.markdown-body::before {
display: table;
content: ""
@SMotaal
SMotaal / README.md
Last active January 13, 2023 20:07
Loading ES Modules in Electron 2.0.0 using Protocol

Now that Electron has hit Chrome's 60s we can have proper module support. But of course, the standard (for very good reasons) prevents loading modules from file: and it makes sense for both Electron and NW.js to adhere to the statusquo.

So if you were really excited and this bums you, don't worry, you are in for awesome things.

The future Electron eco-system offers two options for native ES modules:

  1. Custom Electron protocol via Chromium's module loading subsystem

  2. Custom NodeJS loaders via Node's module loading subsystem recommended

@SMotaal
SMotaal / Proposal.md
Last active December 14, 2018 14:16
ECMAScript Proposal: Non-Module Namespaces

ECMAScript Proposal: Non-Module Namespaces

This is a first draft for a proposal for adding a new dimension to the current ECMAScript module architecture that would make it possible to fulfill platform dependent behaviours for common and non-common requirements without breaking the established compliance criteria. This is not yet a formal proposal.

In the default case of resolving an external dependency (which translates into bindings across two or more linked ES modules) the existing standards are technically sufficient and can only improve by increased adoption and natural progression. However, when it is necessary to either import from or respond to a specific platform, the current standards can be improved upon, which is the topic of several proposals, and is the main focus of this proposal.

Potential Use Cases

// Module-specific
@SMotaal
SMotaal / README.md
Created April 25, 2018 16:53
TypeScript: Support for experimental ".mjs" output

Getting Started

Installing the forked typescript

  yarn add smotaal/TypeScript

Installing typescript-local

* {
font-family: sans-serif;
}
@SMotaal
SMotaal / README.md
Last active June 14, 2018 11:37
Runtime linking for ES2015 Modules [sic]

This prototype simply relies on async execution to walk the module graph and uses the platform to create either a ModuleWrap in node (when possible) or a blob which is used to determine the actual specifier to use for each link outwards.

A given limitation is that circular references will result in deadlock.