Skip to content

Instantly share code, notes, and snippets.

View WebReflection's full-sized avatar
🎯
Focusing

Andrea Giammarchi WebReflection

🎯
Focusing
View GitHub Profile
// React's first tick example using hyperHTML
// https://facebook.github.io/react/docs/state-and-lifecycle.html
function tick(render) {
render`
<div>
<h1>Hello, world!</h1>
<h2>It is ${new Date().toLocaleTimeString()}.</h2>
</div>
`;
}
// WTFPL (C) 2017, Andrea Giammarchi, @WebReflection
class Esimorp extends Promise {
constructor(fn) {
let _resolve, _reject;
super((resolve, reject) => fn(
_resolve = resolve,
_reject = reject
));
this._resolve = _resolve;
this._reject = _reject;

In reply to this post which is a reply to mine


Thanks for taking time to re-explain your PoV on this matter. I'd like to restate mine too, using your arguments.

The idea that you can “always use semicolons” and not worry about Automatic Semicolon Insertion (ASI) is completely incorrect.

You have sneaked in an argument nobody ever mentioned. Not only your suggestion to not use semicolons there wouldn't fix anything, which is why I think we should keep the conversation to examples that make sense instead, but I've also never ever said to not worry about Automatic Semicolon Insertion (ASI).

const post = {
title: '',
published: false
};
const title = document.querySelector('input[name=title]');
const published = document.querySelector('input[name=published]');
// bind post properties to related inputs
wrist.watch(post, 'title', (prop, old, val) => {
const watcher = wrist.watch(
// generic Object or DOM element
generic,
// the property name to watch
'propertyName',
// the callback that will trigger
// only when property value changes
function cb(propName, oldVal, newVal) {
this === generic; // true
propName; // "propertyName"
<!doctype html>
<input name="title">
<input type="checkbox" name="published">
<script>
// given a generic object
const post = {
// we'd like to reflect its properties
// into the DOM view
title: '',
// so that when some value changes
<!doctype html>
<body>
<div>
<h1>clicked <span>0</span> times</h1>
<button
onclick="this.previousElementSibling.firstElementChild.textContent++"
>click</button>
</div>
</body>
function createRandomString(length) {
return String.fromCharCode.apply(
null,
window.crypto.getRandomValues(
new Uint8Array(length)
)
);
}
module.exports = Promise.all([
'./awe',
'./some'
].map(m => module.import(m)))
.then(modules => {
const [awe, some] = modules;
return {awe, some};
});
<!doctype html>
<html>
<script
id="common-js"
data-main="/js-browser/main.js"
src="common.js"
></script>
</html>