-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from rwu823/0.1.3
[0.1.3]
- Loading branch information
Showing
8 changed files
with
4,852 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,5 @@ | ||
{ | ||
"presets": [ | ||
"es2015", | ||
"stage-0" | ||
], | ||
"plugins": [ | ||
"transform-strict-mode" | ||
], | ||
"env": { | ||
"production": { | ||
"plugins": [ | ||
// "transform-remove-console" | ||
] | ||
} | ||
} | ||
"presets": [["env", { | ||
|
||
}]] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,8 @@ | ||
language: node_js | ||
|
||
node_js: | ||
- "v4" | ||
- "v5" | ||
- "v6" | ||
|
||
before_install: | ||
- npm install -g npm | ||
- v6 | ||
- v7 | ||
|
||
after_success: | ||
- npm run coveralls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,62 @@ | ||
import gu from 'gulp' | ||
import rename from 'gulp-rename' | ||
import uglify from 'gulp-uglify' | ||
import pkg from '../package.json' | ||
import del from 'del' | ||
import webpack from 'webpack' | ||
import webpackConf from '../webpack.config' | ||
import fs from 'fs' | ||
import 'shelljs/global' | ||
|
||
import babel from 'rollup-plugin-babel' | ||
import commonjs from 'rollup-plugin-commonjs' | ||
import babelrc from 'babelrc-rollup' | ||
import uglify from 'rollup-plugin-uglify' | ||
|
||
const rollup = require('rollup') | ||
|
||
del.sync('npm') | ||
webpack(webpackConf, (er, stats)=> { | ||
console.log(stats.toString({ | ||
colors: true, | ||
})) | ||
import gu from 'gulp' | ||
import size from 'gulp-size' | ||
|
||
gu.src('npm/dist/*.js') | ||
.pipe(uglify()) | ||
.pipe(rename({ | ||
suffix: '.min' | ||
})) | ||
.pipe(gu.dest('npm/dist')) | ||
rm('-rf', 'npm') | ||
mkdir('-p', 'npm/dist/') | ||
cp('-R', 'README.md', 'npm') | ||
|
||
;(()=> { | ||
const {devDependencies, ava, nyc, scripts, ...pkgJSON} = pkg | ||
rollup.rollup({ | ||
entry: 'src/index.js', | ||
plugins: [ | ||
babel(babelrc({ | ||
addExternalHelpersPlugin: false, | ||
})), | ||
commonjs(), | ||
], | ||
}).then((bundle) => { | ||
const dest = `npm/dist/${pkg.name}.js` | ||
bundle.write({ | ||
dest, | ||
format: 'umd', | ||
moduleName: 'DelegateTo', | ||
}) | ||
|
||
fs.writeFile(`npm/package.json`, JSON.stringify(pkgJSON, null, 2)) | ||
})() | ||
return dest | ||
}) | ||
.then((entry) => { | ||
delete pkg.devDependencies | ||
delete pkg.scripts | ||
|
||
fs.writeFile(`npm/package.json`, JSON.stringify(pkg, null, 2)) | ||
|
||
gu.src('README.md') | ||
.pipe(gu.dest('npm')) | ||
rollup.rollup({ | ||
entry, | ||
plugins: [ | ||
uglify() | ||
], | ||
}).then((bundle) => { | ||
bundle.write({ | ||
dest: `npm/${pkg.main}`, | ||
format: 'umd', | ||
moduleName: 'DelegateTo', | ||
}) | ||
|
||
gu.src('npm/**') | ||
.pipe(size({ | ||
pretty: true, | ||
showFiles: true, | ||
gzip: true, | ||
})) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,5 +30,4 @@ function delegate (selector, dispatchEvent) { | |
} | ||
} | ||
|
||
|
||
module.exports = delegate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,51 @@ | ||
import test from 'ava' | ||
import jsdom from 'jsdom' | ||
import delegate from '../src' | ||
|
||
function setup() { | ||
return new Promise((resolve, reject) => { | ||
jsdom.env(` | ||
<body> | ||
<div id="click-me"> | ||
<h1 id="h1">Click me</h1> | ||
<ul> | ||
<li id="li1">item 1</li> | ||
<li>item 2</li> | ||
<li>item 3</li> | ||
</ul> | ||
</div> | ||
</body>`, (er, window) =>{ | ||
resolve(window) | ||
}) | ||
}) | ||
} | ||
|
||
let win, click, text | ||
test.before(async ()=> { | ||
win = await setup() | ||
|
||
click = win.document.createEvent('HTMLEvents') | ||
click.initEvent('click', true, false) | ||
const win = window | ||
const click = document.createEvent('HTMLEvents') | ||
click.initEvent('click', true, false) | ||
|
||
beforeEach(() => { | ||
document.body.innerHTML = ` | ||
<div id="click-me"> | ||
<h1 id="h1">Click me</h1> | ||
<ul> | ||
<li id="li1">item 1</li> | ||
<li>item 2</li> | ||
<li>item 3</li> | ||
</ul> | ||
</div> | ||
` | ||
}) | ||
|
||
test('delegate li, should output nothing', assert => { | ||
it('delegate li, should output nothing', () => { | ||
let text | ||
win['click-me'].addEventListener('click', delegate('li', e=> { | ||
text = e.target.textContent.trim() | ||
}), false) | ||
|
||
win['click-me'].dispatchEvent(click) | ||
assert.is(text, undefined) | ||
expect(text).toBe(undefined) | ||
|
||
win['h1'].dispatchEvent(click) | ||
assert.is(text, undefined) | ||
window.h1.dispatchEvent(click) | ||
expect(text).toBe(undefined) | ||
}) | ||
|
||
test('delegate li, should output `item 1`', assert => { | ||
win['click-me'].addEventListener('click', delegate('#li', e=> { | ||
it('delegate li, should output `item 1`', () => { | ||
let text | ||
win['click-me'].addEventListener('click', delegate('#li1', e=> { | ||
text = e.delegateTarget.textContent.trim() | ||
}), false) | ||
|
||
win['li1'].dispatchEvent(click) | ||
assert.is(text, 'item 1') | ||
expect(text).toBe('item 1') | ||
}) | ||
|
||
test('delegate li with custom condition, should output `item 1`', assert => { | ||
test('delegate li with custom condition, should output `item 1`', () => { | ||
let text | ||
win['click-me'].addEventListener('click', delegate(target => target.id === 'li1', e=> { | ||
text = e.delegateTarget.textContent.trim() | ||
}), false) | ||
|
||
win['li1'].dispatchEvent(click) | ||
assert.is(text, 'item 1') | ||
expect(text).toBe('item 1') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.