Skip to content

Commit

Permalink
ES2015 module support
Browse files Browse the repository at this point in the history
* compile to intermediary ES module declared in package.json
* compile to CommonJS for Node
* use Rollup to bundle into one file, significantly reducing the amount of Babel garbage in the output, resulting in a much smaller size
  • Loading branch information
mitranim committed Aug 20, 2017
1 parent 33aed9a commit 3aebf3d
Show file tree
Hide file tree
Showing 30 changed files with 632 additions and 1,233 deletions.
2 changes: 1 addition & 1 deletion .babelrc
@@ -1,6 +1,7 @@
{
"plugins": [
"check-es2015-constants",
"external-helpers",
"transform-es2015-arrow-functions",
"transform-es2015-block-scoped-functions",
"transform-es2015-block-scoping",
Expand All @@ -9,7 +10,6 @@
["transform-es2015-classes", {"loose": true}],
"transform-es2015-function-name",
"transform-es2015-literals",
"transform-es2015-modules-commonjs",
"transform-es2015-parameters",
"transform-es2015-shorthand-properties",
["transform-es2015-spread", {"loose": true}],
Expand Down
199 changes: 166 additions & 33 deletions .eslintrc
@@ -1,58 +1,191 @@
{
"parser": "babel-eslint",
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "script"
},
"env": {
"browser": true,
"node": true
"browser": false,
"node": true,
"es6": true
},
"rules": {
"comma-dangle": "off",
"comma-spacing": "error",
"consistent-return": "error",
"curly": ["error", "multi-line"],
"dot-notation": ["error", {"allowKeywords": true}],
"eqeqeq": ["error", "allow-null"],
"indent": ["error", 2, {"SwitchCase": 1}],
"max-len": ["error", 100],
"no-cond-assign": "error",
"no-console": "off",
"no-empty": "off",
// Logic

"no-cond-assign": ["error", "except-parens"],
// "no-constant-condition": "error",
"no-control-regex": "error",
"no-debugger": "error",
"no-dupe-args": "error",
"no-dupe-keys": "error",
"no-duplicate-case": "error",
"no-empty-character-class": "error",
"no-ex-assign": "error",
"no-extra-boolean-cast": "error",
// "no-extra-parens": "error",
"no-extra-semi": "error",
"no-func-assign": "error",
"no-inner-declarations": ["error", "both"],
"no-invalid-regexp": "error",
"no-irregular-whitespace": "error",
"no-obj-calls": "error",
"no-prototype-builtins": "error",
"no-regex-spaces": "error",
"no-sparse-arrays": "error",
"no-template-curly-in-string": "error",
"no-unexpected-multiline": "error",
"no-unreachable": "error",
"no-unsafe-finally": "error",
"no-unsafe-negation": "error",
"use-isnan": "error",
"valid-typeof": "error",
"consistent-return": "error",
"default-case": "error",
"no-case-declarations": "error",
"eqeqeq": ["error", "allow-null"],
"no-else-return": "error",
"no-empty-function": ["error", {"allow": ["functions", "generatorFunctions", "methods", "generatorMethods", "constructors"]}],
"no-empty-pattern": "error",
"no-eval": "error",
"no-extend-native": "error",
"no-extra-bind": "error",
"no-extra-label": "error",
"no-fallthrough": "error",
"no-global-assign": "error",
"no-implicit-coercion": "error",
"no-implicit-globals": "error",
"no-implied-eval": "error",
"no-invalid-this": "error",
// "no-labels": "error",
"no-lone-blocks": "error",
"no-loop-func": "error",
"no-mixed-spaces-and-tabs": "error",
// "no-magic-numbers": "error",
"no-new": "error",
"no-new-func": "error",
"no-new-wrappers": "error",
"no-octal": "error",
"no-octal-escape": "error",
// "no-param-reassign": "error",
"no-proto": "error",
"no-redeclare": "error",
"no-return-assign": "error",
"no-script-url": "error",
"no-self-assign": "error",
"no-self-compare": "error",
"no-sequences": "error",
"no-throw-literal": "error",
"no-unmodified-loop-condition": "error",
"no-unused-expressions": "error",
// "no-unused-labels": "error",
"no-useless-call": "error",
"no-useless-concat": "error",
"no-useless-escape": "error",
"no-useless-return": "error",
"no-with": "error",
"radix": "error",
"require-await": "error",
"init-declarations": ["error", "always"],
"no-delete-var": "error",
"no-restricted-globals": ["error",
// window (browser)
"alert", "blur", "confirm", "event", "fetch", "find", "focus", "history",
"length", "location", "name", "navigator", "open", "parent", "print",
"prompt", "scroll", "self", "status", "stop", "top",
// global (node)
"root"
"root",
// other
"test",
// These global functions are broken
"isNaN", "isFinite"
],
"no-shadow-restricted-names": "error",
"no-sparse-arrays": "off",
"no-throw-literal": "error",
// "no-trailing-spaces": "error",
"no-trailing-spaces": "off",
"no-unexpected-multiline": "error",
"no-unreachable": "error",
"no-unused-expressions": "error",
"no-unused-labels": "off",
"no-unused-vars": ["error", {"argsIgnorePattern": "^_", "varsIgnorePattern": "^_"}],
"no-var": "error",
"object-curly-spacing": ["error", "never"],
"object-shorthand": "error",
"no-undef": "error",
"no-undef-init": "off",
"no-unused-vars": ["error", {"argsIgnorePattern": "^_.", "varsIgnorePattern": "^_."}],
// "no-use-before-define": ["error", {"functions": false, "classes": false}],
// "global-require": "error",
"no-path-concat": "error",
// "no-bitwise": "error",
"strict": ["error", "safe"],

// Style

"curly": ["error", "multi-line"],
// "dot-location": "error",
"dot-notation": "error",
"no-floating-decimal": "error",
// "no-multi-spaces": ["error", {"exceptions": {"VariableDeclarator": true}}],
"no-multi-str": "error",
"no-warning-comments": ["error", {"terms": ["fixme"], "location": "anywhere"}],
"yoda": "error",
"no-label-var": "error",
"array-bracket-spacing": "error",
"block-spacing": ["error", "never"],
"brace-style": ["error", "stroustrup", {"allowSingleLine": true}],
// "camelcase": "error",
"comma-dangle": ["error", "always-multiline"],
"comma-spacing": "error",
"comma-style": "error",
"computed-property-spacing": "error",
"func-call-spacing": "error",
"func-names": ["error", "as-needed"],
// "func-style": ["error", "declaration"],
// "id-length": ["error", {"min": 3}],
"indent": ["error", 2, {"SwitchCase": 1}],
// "key-spacing": ["error", {"align": "value"}],
// "key-spacing": "error",
"keyword-spacing": "error",
"lines-around-comment": "error",
"lines-around-directive": "error",
"max-len": ["error", {"code": 120}],
// "new-cap": "error",
"new-parens": "error",
"no-array-constructor": "error",
"no-lonely-if": "error",
"no-mixed-operators": "error",
"no-mixed-spaces-and-tabs": "error",
// "no-multiple-empty-lines": "error",
"no-new-object": "error",
// "no-plusplus": "error",
"no-tabs": "error",
"no-unneeded-ternary": "error",
"no-whitespace-before-property": "error",
// "object-curly-newline": "error",
"object-curly-spacing": "error",
"one-var": ["error", "never"],
"prefer-const": "error",
"operator-assignment": ["error", "always"],
"operator-linebreak": ["error", "after", {"overrides": {"?": "off", ":": "off"}}],
"padded-blocks": ["error", "never"],
"quote-props": ["error", "as-needed"],
"quotes": ["error", "single", {"avoidEscape": true, "allowTemplateLiterals": true}],
"quotes": ["error", "single", {"allowTemplateLiterals": true, "avoidEscape": true}],
"semi": ["error", "never"],
"space-before-blocks": ["error", "always"],
"space-in-parens": ["error", "never"],
"space-in-parens": "error",
"space-infix-ops": "error",
"space-unary-ops": "error",
"spaced-comment": ["error", "always"],
"valid-typeof": "error",
"yoda": "error"
// "arrow-body-style": ["error", "as-needed"],
"arrow-parens": ["error", "as-needed"],
"arrow-spacing": "error",
"constructor-super": "error",
"generator-star-spacing": ["error", "after"],
"no-class-assign": "error",
// "no-confusing-arrow": "error",
"no-const-assign": "error",
"no-dupe-class-members": "error",
"no-duplicate-imports": "error",
"no-new-symbol": "error",
"no-this-before-super": "error",
"no-useless-computed-key": "error",
"no-useless-constructor": "error",
"no-useless-rename": "error",
"no-var": "error",
"object-shorthand": "error",
"prefer-const": "error",
"prefer-numeric-literals": "error",
"prefer-spread": "error",
"prefer-template": "error",
// "require-yield": "error",
"rest-spread-spacing": "error",
"template-curly-spacing": "error"
}
}
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -4,6 +4,7 @@

# Folders
dist
es
gh-pages
node_modules
mocks
2 changes: 1 addition & 1 deletion .travis.yml
@@ -1,6 +1,6 @@
language: node_js
node_js: node
script: yarn run build
script: yarn run compile
cache: yarn
deploy:
provider: pages
Expand Down
3 changes: 2 additions & 1 deletion docs/html/partials/overview.md
Expand Up @@ -6,7 +6,8 @@ Source <span class="fa fa-github"></span>
</a>

Library for stateful and reactive programming: queues, observables, ownership
and lifetimes, procedural reactivity. Lightweight alternative to RxJS.
and lifetimes, procedural reactivity. Lightweight alternative to RxJS for GUI
programs.

See sibling library [`fpx`](https://mitranim.com/fpx/) for functional
programming utils.
Expand Down
10 changes: 10 additions & 0 deletions docs/scripts/.eslintrc
@@ -0,0 +1,10 @@
{
"env": {
"browser": true,
"node": false,
"es6": false
},
"parserOptions": {
"sourceType": "module"
}
}
18 changes: 10 additions & 8 deletions docs/scripts/docs.js
@@ -1,7 +1,7 @@
const {bind, procure} = require('fpx')
const {global, assign, each} = require('espo')
const {Throttle, getVisibleId, hasAttr, preventScrollSpill, findParent,
setHash, unsetHash, scrollIntoViewIfNeeded} = require('./utils')
import {bind, procure} from 'fpx'
import {global, assign, each} from 'espo'
import {Throttle, getVisibleId, hasAttr, preventScrollSpill, findParent,
setHash, unsetHash, scrollIntoViewIfNeeded} from './utils'

const scroller = new Throttle(updateLinksAndHash, {delay: 250})

Expand Down Expand Up @@ -50,11 +50,13 @@ function deactivate (elem) {

// REPL

const fpx = require('fpx')
const espo = require('espo')
const emerge = require('emerge')
/* eslint-disable no-duplicate-imports */

assign(exports, {fpx, emerge, espo, scroller}, fpx, emerge, espo)
import * as fpx from 'fpx'
import * as espo from 'espo'
import * as emerge from 'emerge'

const exports = assign({}, {fpx, emerge, espo, scroller}, fpx, emerge, espo)

delete exports.isNaN
delete exports.isFinite
Expand Down
28 changes: 15 additions & 13 deletions docs/scripts/utils.js
@@ -1,5 +1,7 @@
const {get, and, truthy, isFunction, validate} = require('fpx')
const {global, global: {history}} = require('espo')
import {get, and, truthy, isFunction, validate} from 'fpx'
import {global} from 'espo'

const {history} = global

// Pixel measurements are inaccurate when the browser is zoomed in or out, so we
// have to use a small non-zero value in some geometry checks.
Expand All @@ -16,7 +18,7 @@ export class Throttle {

run () {
if (this.timerId) this.tailPending = true
else restartThrottle.call(this)
else restartThrottle(this)
}

isPending () {
Expand All @@ -29,14 +31,14 @@ export class Throttle {
}
}

function restartThrottle () {
this.stop()
this.timerId = setTimeout(() => {
this.timerId = null
if (this.tailPending) restartThrottle.call(this)
this.tailPending = false
this.fun(...arguments)
}, get(this.options, 'delay'))
function restartThrottle (throttle) {
throttle.stop()
throttle.timerId = setTimeout(() => {
throttle.timerId = null
if (throttle.tailPending) restartThrottle(throttle)
throttle.tailPending = false
throttle.fun(...arguments)
}, get(throttle.options, 'delay'))
}

export const getVisibleId = and(truthy, hasArea, withinViewport, elem => elem.id)
Expand All @@ -57,8 +59,8 @@ function hasArea (elem) {
function withinViewport (elem) {
const {top, bottom} = elem.getBoundingClientRect()
return (
bottom > -PX_ERROR_MARGIN && bottom < global.innerHeight ||
top > PX_ERROR_MARGIN && top < (global.innerHeight + PX_ERROR_MARGIN)
bottom > (-PX_ERROR_MARGIN && bottom < global.innerHeight) ||
top > (PX_ERROR_MARGIN && top < (global.innerHeight + PX_ERROR_MARGIN))
)
}

Expand Down

0 comments on commit 3aebf3d

Please sign in to comment.