├── .gitignore ├── .eslintrc.json ├── .travis.yml ├── test ├── .eslintrc.json ├── vendor │ ├── saucelabs-reporting.js │ ├── load-script-series.js │ ├── rAF.js │ └── es6-set.js ├── test.html └── test.change.js ├── LICENSE ├── package.json ├── README.md ├── Gruntfile.js └── lib └── change.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "airbnb-base/legacy", 3 | "rules": { 4 | "no-param-reassign": ["error", { "props": false }] 5 | } 6 | } -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | addons: 2 | sauce_connect: true 3 | 4 | language: node_js 5 | node_js: node 6 | 7 | script: npm run lint && npm run build && npm test 8 | -------------------------------------------------------------------------------- /test/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "airbnb-base/legacy", 3 | "env": { 4 | "mocha": true 5 | }, 6 | "rules": { 7 | "func-names": 0 8 | }, 9 | "globals": { 10 | "chai": false, 11 | "React": false, 12 | "ReactDOM": false, 13 | "reactTriggerChange": false 14 | } 15 | } -------------------------------------------------------------------------------- /test/vendor/saucelabs-reporting.js: -------------------------------------------------------------------------------- 1 | (function saucelabsReportingScope() { 2 | 'use strict'; 3 | 4 | function flattenTitles(leafTest) { 5 | var titles = []; 6 | var test = leafTest; 7 | while (test.parent.title) { 8 | titles.push(test.parent.title); 9 | test = test.parent; 10 | } 11 | return titles.reverse(); 12 | } 13 | 14 | function saucelabsReporting(runner) { 15 | var failedTests = []; 16 | 17 | runner.on('fail', function logFailure(test, err) { 18 | failedTests.push({ 19 | name: test.title, 20 | result: false, 21 | message: err.message, 22 | stack: err.stack, 23 | titles: flattenTitles(test) 24 | }); 25 | }); 26 | 27 | runner.on('end', function reportTestsComplete() { 28 | window.mochaResults = runner.stats; 29 | window.mochaResults.reports = failedTests; 30 | }); 31 | } 32 | 33 | // Exports 34 | window.saucelabsReporting = saucelabsReporting; 35 | }()); 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Vitaly Kuznetsov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-trigger-change", 3 | "version": "1.0.2", 4 | "description": "Trigger React's synthetic change events on input, textarea and select elements", 5 | "license": "MIT", 6 | "repository": "vitalyq/react-trigger-change", 7 | "author": "Vitaly Kuznetsov", 8 | "main": "lib/change.js", 9 | "scripts": { 10 | "lint": "eslint lib \"test/*.js\"", 11 | "build:dev": "webpack lib/change.js dist/react-trigger-change.js --output-library=reactTriggerChange --output-library-target=umd", 12 | "build:min": "webpack lib/change.js dist/react-trigger-change.min.js -p --output-library=reactTriggerChange --output-library-target=umd", 13 | "build": "npm run build:dev && npm run build:min", 14 | "test": "grunt" 15 | }, 16 | "devDependencies": { 17 | "eslint": "3.19.0", 18 | "eslint-config-airbnb-base": "11.1.3", 19 | "eslint-plugin-import": "2.2.0", 20 | "grunt": "^1.0.1", 21 | "grunt-contrib-connect": "^1.0.2", 22 | "grunt-saucelabs": "^9.0.0", 23 | "webpack": "^2.3.2" 24 | }, 25 | "files": [ 26 | "lib", 27 | "dist" 28 | ], 29 | "keywords": [ 30 | "react", 31 | "trigger", 32 | "dispatch", 33 | "change", 34 | "event" 35 | ] 36 | } 37 | -------------------------------------------------------------------------------- /test/vendor/load-script-series.js: -------------------------------------------------------------------------------- 1 | (function loadScriptSeriesScope() { 2 | 'use strict'; 3 | 4 | function loadScript(url, callback) { 5 | var done = false; 6 | var head = document.getElementsByTagName('head')[0]; 7 | var script = document.createElement('script'); 8 | 9 | function handleLoad() { 10 | if (!done && (!this.readyState || 11 | this.readyState === 'loaded' || 12 | this.readyState === 'complete')) { 13 | done = true; 14 | 15 | // Handle memory leak in IE. 16 | script.onload = null; 17 | script.onreadystatechange = null; 18 | head.removeChild(script); 19 | 20 | callback(); 21 | } 22 | } 23 | 24 | script.src = url; 25 | script.onload = handleLoad; 26 | script.onreadystatechange = handleLoad; 27 | head.appendChild(script); 28 | } 29 | 30 | function loadScriptSeries(urls, callback) { 31 | var i = 0; 32 | function onLoad() { 33 | i += 1; 34 | if (i !== urls.length) { 35 | loadScript(urls[i], onLoad); 36 | } else { 37 | callback(); 38 | } 39 | } 40 | 41 | loadScript(urls[0], onLoad); 42 | } 43 | 44 | // Exports 45 | window.loadScriptSeries = loadScriptSeries; 46 | }()); 47 | -------------------------------------------------------------------------------- /test/vendor/rAF.js: -------------------------------------------------------------------------------- 1 | // http://paulirish.com/2011/requestanimationframe-for-smart-animating/ 2 | // http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating 3 | 4 | // requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel 5 | 6 | // MIT license 7 | 8 | (function() { 9 | var lastTime = 0; 10 | var vendors = ['ms', 'moz', 'webkit', 'o']; 11 | for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { 12 | window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame']; 13 | window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame'] 14 | || window[vendors[x]+'CancelRequestAnimationFrame']; 15 | } 16 | 17 | if (!window.requestAnimationFrame) 18 | window.requestAnimationFrame = function(callback, element) { 19 | var currTime = new Date().getTime(); 20 | var timeToCall = Math.max(0, 16 - (currTime - lastTime)); 21 | var id = window.setTimeout(function() { callback(currTime + timeToCall); }, 22 | timeToCall); 23 | lastTime = currTime + timeToCall; 24 | return id; 25 | }; 26 | 27 | if (!window.cancelAnimationFrame) 28 | window.cancelAnimationFrame = function(id) { 29 | clearTimeout(id); 30 | }; 31 | }()); -------------------------------------------------------------------------------- /test/test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Mocha Tests 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 36 | 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # react-trigger-change [![Build Status](https://img.shields.io/travis/vitalyq/react-trigger-change.svg)](https://travis-ci.org/vitalyq/react-trigger-change) [![Npm Version](https://img.shields.io/npm/v/react-trigger-change.svg)](https://www.npmjs.com/package/react-trigger-change) 2 | 3 | [![Build Status](https://saucelabs.com/browser-matrix/vitalyq.svg)](https://saucelabs.com/u/vitalyq) 4 | 5 | Library for triggering [React](https://github.com/facebook/react/)'s synthetic change events on input, textarea and select elements. 6 | 7 | In production builds of React `ReactTestUtils.Simulate` doesn't work because of dead code elimination. There is no other built-in way to dispatch synthetic change events. 8 | 9 | This module is a hack and is tightly coupled with React's implementation details. Not intended for production use. Useful for end-to-end testing and debugging. 10 | 11 | ## Install 12 | 13 | With npm: 14 | 15 | ``` 16 | npm install react-trigger-change --save-dev 17 | ``` 18 | 19 | From a CDN: 20 | 21 | ```HTML 22 | 23 | ``` 24 | 25 | ## Use 26 | 27 | ```JSX 28 | reactTriggerChange(DOMElement); 29 | ``` 30 | 31 | *DOMElement* - native DOM element, will be the target of change event. 32 | 33 | One way to obtain a DOM element in React is to use `ref` attribute: 34 | 35 | ```JSX 36 | let node; 37 | ReactDOM.render( 38 | console.log('changed')} 40 | ref={(input) => { node = input; }} 41 | />, 42 | mountNode 43 | ); 44 | 45 | reactTriggerChange(node); // 'changed' is logged 46 | ``` 47 | 48 | ## Test 49 | 50 | Build the browser bundle: 51 | 52 | ``` 53 | npm install 54 | npm run build 55 | ``` 56 | 57 | Open `test/test.html` in the browser. 58 | 59 | To test with a different version of React, specify React and ReactDOM URLs in a query string: 60 | 61 | ``` 62 | ?react=https://unpkg.com/react@16.2.0/umd/react.development.js&dom=https://unpkg.com/react-dom@16.2.0/umd/react-dom.development.js 63 | ``` 64 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | // SauceLabs unit tests setup. 2 | 3 | module.exports = function gruntConfig(grunt) { 4 | var browsers = [ 5 | { browserName: 'chrome', version: '63.0', platform: 'Windows 10' }, 6 | { browserName: 'firefox', version: '58.0', platform: 'Windows 10' }, 7 | { browserName: 'safari', version: '8.0', platform: 'OS X 10.10' }, 8 | { browserName: 'MicrosoftEdge', version: '14.14393', platform: 'Windows 10' }, 9 | { browserName: 'internet explorer', version: '11.0', platform: 'Windows 8.1' }, 10 | { browserName: 'internet explorer', version: '10.0', platform: 'Windows 8' }, 11 | { browserName: 'internet explorer', version: '9.0', platform: 'Windows 7' } 12 | ]; 13 | var testURL = 'http://127.0.0.1:9999/test/test.html'; 14 | var cdnURL = 'https://unpkg.com/'; 15 | var reactPaths = [ 16 | ['react@15.6.2/dist/react.min.js', 17 | 'react-dom@15.6.2/dist/react-dom.min.js'], 18 | ['react@16.2.0/umd/react.production.min.js', 19 | 'react-dom@16.2.0/umd/react-dom.production.min.js'] 20 | ]; 21 | var urls = reactPaths.map(function mapPaths(path) { 22 | return testURL + '?react=' + cdnURL + path[0] + '&dom=' + cdnURL + path[1]; 23 | }); 24 | 25 | grunt.initConfig({ 26 | pkg: grunt.file.readJSON('package.json'), 27 | connect: { 28 | server: { 29 | options: { 30 | base: '', 31 | port: 9999 32 | } 33 | } 34 | }, 35 | 'saucelabs-mocha': { 36 | all: { 37 | options: { 38 | urls: urls, 39 | browsers: browsers, 40 | build: process.env.TRAVIS_JOB_ID, 41 | testname: 'unit tests', 42 | throttled: 5, 43 | sauceConfig: { 44 | recordVideo: false, 45 | recordScreenshots: false, 46 | tunnelIdentifier: process.env.TRAVIS_JOB_NUMBER 47 | }, 48 | tunneled: false 49 | } 50 | } 51 | }, 52 | watch: {} 53 | }); 54 | 55 | grunt.loadNpmTasks('grunt-contrib-connect'); 56 | grunt.loadNpmTasks('grunt-saucelabs'); 57 | 58 | grunt.registerTask('default', ['connect', 'saucelabs-mocha']); 59 | }; 60 | -------------------------------------------------------------------------------- /lib/change.js: -------------------------------------------------------------------------------- 1 | // Trigger React's synthetic change events on input, textarea and select elements 2 | // https://github.com/facebook/react/pull/4051 - React 15 fix 3 | // https://github.com/facebook/react/pull/5746 - React 16 fix 4 | 5 | 'use strict'; 6 | 7 | // Constants and functions are declared inside the closure. 8 | // In this way, reactTriggerChange can be passed directly to executeScript in Selenium. 9 | module.exports = function reactTriggerChange(node) { 10 | var supportedInputTypes = { 11 | color: true, 12 | date: true, 13 | datetime: true, 14 | 'datetime-local': true, 15 | email: true, 16 | month: true, 17 | number: true, 18 | password: true, 19 | range: true, 20 | search: true, 21 | tel: true, 22 | text: true, 23 | time: true, 24 | url: true, 25 | week: true 26 | }; 27 | var nodeName = node.nodeName.toLowerCase(); 28 | var type = node.type; 29 | var event; 30 | var descriptor; 31 | var initialValue; 32 | var initialChecked; 33 | var initialCheckedRadio; 34 | 35 | // Do not try to delete non-configurable properties. 36 | // Value and checked properties on DOM elements are non-configurable in PhantomJS. 37 | function deletePropertySafe(elem, prop) { 38 | var desc = Object.getOwnPropertyDescriptor(elem, prop); 39 | if (desc && desc.configurable) { 40 | delete elem[prop]; 41 | } 42 | } 43 | 44 | // In IE10 propertychange is not dispatched on range input if invalid 45 | // value is set. 46 | function changeRangeValue(range) { 47 | var initMin = range.min; 48 | var initMax = range.max; 49 | var initStep = range.step; 50 | var initVal = Number(range.value); 51 | 52 | range.min = initVal; 53 | range.max = initVal + 1; 54 | range.step = 1; 55 | range.value = initVal + 1; 56 | deletePropertySafe(range, 'value'); 57 | range.min = initMin; 58 | range.max = initMax; 59 | range.step = initStep; 60 | range.value = initVal; 61 | } 62 | 63 | function getCheckedRadio(radio) { 64 | var name = radio.name; 65 | var radios; 66 | var i; 67 | if (name) { 68 | radios = document.querySelectorAll('input[type="radio"][name="' + name + '"]'); 69 | for (i = 0; i < radios.length; i += 1) { 70 | if (radios[i].checked) { 71 | return radios[i] !== radio ? radios[i] : null; 72 | } 73 | } 74 | } 75 | return null; 76 | } 77 | 78 | function preventChecking(e) { 79 | e.preventDefault(); 80 | if (!initialChecked) { 81 | e.target.checked = false; 82 | } 83 | if (initialCheckedRadio) { 84 | initialCheckedRadio.checked = true; 85 | } 86 | } 87 | 88 | if (nodeName === 'select' || 89 | (nodeName === 'input' && type === 'file')) { 90 | // IE9-IE11, non-IE 91 | // Dispatch change. 92 | event = document.createEvent('HTMLEvents'); 93 | event.initEvent('change', true, false); 94 | node.dispatchEvent(event); 95 | } else if ((nodeName === 'input' && supportedInputTypes[type]) || 96 | nodeName === 'textarea') { 97 | // React 16 98 | // Cache artificial value property descriptor. 99 | // Property doesn't exist in React <16, descriptor is undefined. 100 | descriptor = Object.getOwnPropertyDescriptor(node, 'value'); 101 | 102 | // React 0.14: IE9 103 | // React 15: IE9-IE11 104 | // React 16: IE9 105 | // Dispatch focus. 106 | event = document.createEvent('UIEvents'); 107 | event.initEvent('focus', false, false); 108 | node.dispatchEvent(event); 109 | 110 | // React 0.14: IE9 111 | // React 15: IE9-IE11 112 | // React 16 113 | // In IE9-10 imperative change of node value triggers propertychange event. 114 | // Update inputValueTracking cached value. 115 | // Remove artificial value property. 116 | // Restore initial value to trigger event with it. 117 | if (type === 'range') { 118 | changeRangeValue(node); 119 | } else { 120 | initialValue = node.value; 121 | node.value = initialValue + '#'; 122 | deletePropertySafe(node, 'value'); 123 | node.value = initialValue; 124 | } 125 | 126 | // React 15: IE11 127 | // For unknown reason React 15 added listener for propertychange with addEventListener. 128 | // This doesn't work, propertychange events are deprecated in IE11, 129 | // but allows us to dispatch fake propertychange which is handled by IE11. 130 | event = document.createEvent('HTMLEvents'); 131 | event.initEvent('propertychange', false, false); 132 | event.propertyName = 'value'; 133 | node.dispatchEvent(event); 134 | 135 | // React 0.14: IE10-IE11, non-IE 136 | // React 15: non-IE 137 | // React 16: IE10-IE11, non-IE 138 | event = document.createEvent('HTMLEvents'); 139 | event.initEvent('input', true, false); 140 | node.dispatchEvent(event); 141 | 142 | // React 16 143 | // Restore artificial value property descriptor. 144 | if (descriptor) { 145 | Object.defineProperty(node, 'value', descriptor); 146 | } 147 | } else if (nodeName === 'input' && type === 'checkbox') { 148 | // Invert inputValueTracking cached value. 149 | node.checked = !node.checked; 150 | 151 | // Dispatch click. 152 | // Click event inverts checked value. 153 | event = document.createEvent('MouseEvents'); 154 | event.initEvent('click', true, true); 155 | node.dispatchEvent(event); 156 | } else if (nodeName === 'input' && type === 'radio') { 157 | // Cache initial checked value. 158 | initialChecked = node.checked; 159 | 160 | // Find and cache initially checked radio in the group. 161 | initialCheckedRadio = getCheckedRadio(node); 162 | 163 | // React 16 164 | // Cache property descriptor. 165 | // Invert inputValueTracking cached value. 166 | // Remove artificial checked property. 167 | // Restore initial value, otherwise preventDefault will eventually revert the value. 168 | descriptor = Object.getOwnPropertyDescriptor(node, 'checked'); 169 | node.checked = !initialChecked; 170 | deletePropertySafe(node, 'checked'); 171 | node.checked = initialChecked; 172 | 173 | // Prevent toggling during event capturing phase. 174 | // Set checked value to false if initialChecked is false, 175 | // otherwise next listeners will see true. 176 | // Restore initially checked radio in the group. 177 | node.addEventListener('click', preventChecking, true); 178 | 179 | // Dispatch click. 180 | // Click event inverts checked value. 181 | event = document.createEvent('MouseEvents'); 182 | event.initEvent('click', true, true); 183 | node.dispatchEvent(event); 184 | 185 | // Remove listener to stop further change prevention. 186 | node.removeEventListener('click', preventChecking, true); 187 | 188 | // React 16 189 | // Restore artificial checked property descriptor. 190 | if (descriptor) { 191 | Object.defineProperty(node, 'checked', descriptor); 192 | } 193 | } 194 | }; 195 | -------------------------------------------------------------------------------- /test/test.change.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | describe('#reactTriggerChange', function () { 4 | var assert = chai.assert; 5 | var render = ReactDOM.render; 6 | var createElement = React.createElement; 7 | var container; 8 | var node; 9 | var changes; 10 | 11 | function getReference(element) { 12 | node = element; 13 | } 14 | 15 | function handleChange() { 16 | changes += 1; 17 | } 18 | 19 | function triggerAndCheck() { 20 | assert.strictEqual(changes, 0, 'change was triggered too early'); 21 | reactTriggerChange(node); 22 | assert.notStrictEqual(changes, 0, 'change was not triggered'); 23 | assert.strictEqual(changes, 1, 'change was triggered multiple times'); 24 | } 25 | 26 | function getCheckProperty(props) { 27 | return ( 28 | 'checked' in props || 29 | 'defaultChecked' in props ? 30 | 'checked' : 'value'); 31 | } 32 | 33 | function getExpectedValue(props) { 34 | var expected; 35 | [ 36 | 'value', 'defaultValue', 37 | 'checked', 'defaultChecked' 38 | ].some(function (key) { 39 | if (key in props) { 40 | expected = props[key]; 41 | return true; 42 | } 43 | return false; 44 | }); 45 | return expected; 46 | } 47 | 48 | // title - test title. 49 | // options.tag - tag name to create. 50 | // options.props - props object. 51 | function createTest(title, options) { 52 | it(title, function () { 53 | var tag = options.tag; 54 | var props = options.props; 55 | var checkProperty = getCheckProperty(props); 56 | var expected = getExpectedValue(props); 57 | 58 | function handleChangeLocal() { 59 | // If checkbox is toggled manually, this will throw. 60 | assert.strictEqual(node[checkProperty], expected); 61 | changes += 1; 62 | } 63 | 64 | props.ref = getReference; 65 | props.onChange = handleChangeLocal; 66 | render(createElement(tag, props), container); 67 | triggerAndCheck(); 68 | assert.strictEqual(node[checkProperty], expected); 69 | }); 70 | } 71 | 72 | function createDescriptorTest(title, options) { 73 | it(title, function () { 74 | var tag = options.tag; 75 | var props = options.props; 76 | var checkProperty = getCheckProperty(props); 77 | var descriptorFirst; 78 | var descriptorLast; 79 | 80 | props.ref = getReference; 81 | render(createElement(tag, props), container); 82 | 83 | descriptorFirst = Object.getOwnPropertyDescriptor(node, checkProperty); 84 | if (descriptorFirst) { 85 | reactTriggerChange(node); 86 | descriptorLast = Object.getOwnPropertyDescriptor(node, checkProperty); 87 | assert.strictEqual(descriptorLast.configurable, descriptorFirst.configurable); 88 | assert.strictEqual(descriptorLast.enumerable, descriptorFirst.enumerable); 89 | assert.strictEqual(descriptorLast.get, descriptorFirst.get); 90 | assert.strictEqual(descriptorLast.set, descriptorFirst.set); 91 | } 92 | }); 93 | } 94 | 95 | beforeEach(function () { 96 | changes = 0; 97 | container = document.createElement('div'); 98 | container.id = 'root'; 99 | document.body.appendChild(container); 100 | }); 101 | 102 | afterEach(function () { 103 | document.body.removeChild(container); 104 | }); 105 | 106 | describe('on select', function () { 107 | it('should not change index (controlled)', function () { 108 | function handleChangeLocal() { 109 | assert.strictEqual(node.selectedIndex, 1); 110 | assert.strictEqual(node.value, 'opt2'); 111 | changes += 1; 112 | } 113 | 114 | render( 115 | createElement('select', 116 | { value: 'opt2', ref: getReference, onChange: handleChangeLocal }, 117 | createElement('option', { value: 'opt1' }, 'Option 1'), 118 | createElement('option', { value: 'opt2' }, 'Option 2') 119 | ), 120 | container 121 | ); 122 | triggerAndCheck(); 123 | handleChangeLocal(); 124 | }); 125 | 126 | it('should not change index (uncontrolled)', function () { 127 | function handleChangeLocal() { 128 | assert.strictEqual(node.selectedIndex, 1); 129 | assert.strictEqual(node.value, 'opt2'); 130 | changes += 1; 131 | } 132 | 133 | render( 134 | createElement('select', 135 | { defaultValue: 'opt2', ref: getReference, onChange: handleChangeLocal }, 136 | createElement('option', { value: 'opt1' }, 'Option 1'), 137 | createElement('option', { value: 'opt2' }, 'Option 2') 138 | ), 139 | container 140 | ); 141 | 142 | triggerAndCheck(); 143 | handleChangeLocal(); 144 | }); 145 | }); 146 | 147 | describe('on file input', function () { 148 | it('should support file input', function () { 149 | render( 150 | createElement('input', { type: 'file', ref: getReference, onChange: handleChange }), 151 | container 152 | ); 153 | triggerAndCheck(); 154 | }); 155 | }); 156 | 157 | describe('on text input', function () { 158 | var supportedInputTypes = { 159 | color: { filled: '#ff00ff', empty: '#000000' }, 160 | date: { filled: '2017-03-24', empty: '' }, 161 | datetime: { filled: '2017-03-29T11:11', empty: '' }, 162 | 'datetime-local': { filled: '2017-03-29T11:11', empty: '' }, 163 | email: { filled: '5', empty: '' }, 164 | month: { filled: '2017-03', empty: '' }, 165 | number: { filled: '5', empty: '' }, 166 | password: { filled: '5', empty: '' }, 167 | range: { filled: '5', empty: '50' }, 168 | search: { filled: '5', empty: '' }, 169 | tel: { filled: '5', empty: '' }, 170 | text: { filled: '5', empty: '' }, 171 | time: { filled: '14:14', empty: '' }, 172 | url: { filled: '5', empty: '' }, 173 | week: { filled: '2017-W11', empty: '' } 174 | }; 175 | 176 | var maxlengthSupport = { 177 | email: true, 178 | password: true, 179 | search: true, 180 | tel: true, 181 | text: true, 182 | url: true 183 | }; 184 | 185 | createDescriptorTest('should reattach value property descriptor (React 16)', { 186 | tag: 'input', 187 | props: { defaultValue: '' } 188 | }); 189 | 190 | describe('(controlled)', function () { 191 | describe('should not change empty value on input of type', function () { 192 | Object.keys(supportedInputTypes).forEach(function (type) { 193 | createTest(type, { 194 | tag: 'input', 195 | props: { value: supportedInputTypes[type].empty, type: type } 196 | }); 197 | }); 198 | createTest('textarea', { 199 | tag: 'textarea', 200 | props: { value: '' } 201 | }); 202 | }); 203 | 204 | describe('should not change non-empty value on input of type', function () { 205 | Object.keys(supportedInputTypes).forEach(function (type) { 206 | createTest(type, { 207 | tag: 'input', 208 | props: { value: supportedInputTypes[type].filled, type: type } 209 | }); 210 | }); 211 | createTest('textarea', { 212 | tag: 'textarea', 213 | props: { value: '5' } 214 | }); 215 | }); 216 | 217 | describe('should support maxlength attribute on input of type', function () { 218 | Object.keys(maxlengthSupport).forEach(function (type) { 219 | createTest(type, { 220 | tag: 'input', 221 | props: { value: supportedInputTypes[type].filled, type: type, maxLength: 1 } 222 | }); 223 | }); 224 | createTest('textarea', { 225 | tag: 'textarea', 226 | props: { value: '5', maxLength: 1 } 227 | }); 228 | }); 229 | }); 230 | 231 | describe('(uncontrolled)', function () { 232 | describe('should not change empty value on input of type', function () { 233 | Object.keys(supportedInputTypes).forEach(function (type) { 234 | createTest(type, { 235 | tag: 'input', 236 | props: { defaultValue: supportedInputTypes[type].empty, type: type } 237 | }); 238 | }); 239 | createTest('textarea', { 240 | tag: 'textarea', 241 | props: { defaultValue: '' } 242 | }); 243 | }); 244 | 245 | describe('should not change non-empty value on input of type', function () { 246 | Object.keys(supportedInputTypes).forEach(function (type) { 247 | createTest(type, { 248 | tag: 'input', 249 | props: { defaultValue: supportedInputTypes[type].filled, type: type } 250 | }); 251 | }); 252 | createTest('textarea', { 253 | tag: 'textarea', 254 | props: { defaultValue: '5' } 255 | }); 256 | }); 257 | 258 | describe('should support maxlength attribute on input of type', function () { 259 | Object.keys(maxlengthSupport).forEach(function (type) { 260 | createTest(type, { 261 | tag: 'input', 262 | props: { defaultValue: supportedInputTypes[type].filled, type: type, maxLength: 1 } 263 | }); 264 | }); 265 | createTest('textarea', { 266 | tag: 'textarea', 267 | props: { defaultValue: '5', maxLength: 1 } 268 | }); 269 | }); 270 | }); 271 | }); 272 | 273 | describe('on checkbox', function () { 274 | describe('(controlled)', function () { 275 | createTest('should not toggle unchecked', { 276 | tag: 'input', 277 | props: { checked: false, type: 'checkbox' } 278 | }); 279 | 280 | createTest('should not toggle checked', { 281 | tag: 'input', 282 | props: { checked: true, type: 'checkbox' } 283 | }); 284 | }); 285 | 286 | describe('(uncontrolled)', function () { 287 | createTest('should not toggle unchecked', { 288 | tag: 'input', 289 | props: { defaultChecked: false, type: 'checkbox' } 290 | }); 291 | 292 | createTest('should not toggle checked', { 293 | tag: 'input', 294 | props: { defaultChecked: true, type: 'checkbox' } 295 | }); 296 | }); 297 | }); 298 | 299 | describe('on radio', function () { 300 | createDescriptorTest('should reattach checked property descriptor (React 16)', { 301 | tag: 'input', 302 | props: { defaultChecked: false, type: 'radio' } 303 | }); 304 | 305 | describe('(controlled)', function () { 306 | createTest('should not toggle unchecked', { 307 | tag: 'input', 308 | props: { checked: false, type: 'radio' } 309 | }); 310 | 311 | createTest('should not toggle checked', { 312 | tag: 'input', 313 | props: { checked: true, type: 'radio' } 314 | }); 315 | }); 316 | 317 | describe('(uncontrolled)', function () { 318 | createTest('should not toggle unchecked', { 319 | tag: 'input', 320 | props: { defaultChecked: false, type: 'radio' } 321 | }); 322 | 323 | createTest('should not toggle checked', { 324 | tag: 'input', 325 | props: { defaultChecked: true, type: 'radio' } 326 | }); 327 | }); 328 | }); 329 | 330 | describe('on radio group', function () { 331 | describe('should not toggle any or trigger change on partner', function () { 332 | function createRadioGroupTest(title, controlled, selfVal, partnerVal) { 333 | it(title, function () { 334 | var partner; 335 | var selfProps; 336 | var partnerProps; 337 | var valueProp = controlled ? 'checked' : 'defaultChecked'; 338 | 339 | function handleChangeLocal() { 340 | assert.strictEqual(node.checked, selfVal, 'self value toggled'); 341 | assert.strictEqual(partner.checked, partnerVal, 'partner value toggled'); 342 | changes += 1; 343 | } 344 | 345 | function getPartner(element) { 346 | partner = element; 347 | } 348 | 349 | function fail() { 350 | assert.fail(null, null, 'change triggered on partner'); 351 | } 352 | 353 | selfProps = { 354 | ref: getReference, 355 | onChange: handleChangeLocal, 356 | name: 'foo', 357 | type: 'radio' 358 | }; 359 | selfProps[valueProp] = selfVal; 360 | 361 | partnerProps = { 362 | ref: getPartner, 363 | onChange: fail, 364 | name: 'foo', 365 | type: 'radio' 366 | }; 367 | partnerProps[valueProp] = partnerVal; 368 | 369 | render( 370 | createElement('div', null, 371 | createElement('input', selfProps), 372 | createElement('input', partnerProps)), 373 | container 374 | ); 375 | 376 | triggerAndCheck(); 377 | handleChangeLocal(); 378 | }); 379 | } 380 | 381 | describe('(controlled)', function () { 382 | var controlled = true; 383 | createRadioGroupTest('when botch unchecked', controlled, false, false); 384 | createRadioGroupTest('when self checked and partner unchecked', controlled, true, false); 385 | createRadioGroupTest('when self unchecked and partner checked', controlled, false, true); 386 | }); 387 | 388 | describe('(uncontrolled)', function () { 389 | var controlled = false; 390 | createRadioGroupTest('when botch unchecked', controlled, false, false); 391 | createRadioGroupTest('when self checked and partner unchecked', controlled, true, false); 392 | createRadioGroupTest('when self unchecked and partner checked', controlled, false, true); 393 | }); 394 | }); 395 | }); 396 | }); 397 | -------------------------------------------------------------------------------- /test/vendor/es6-set.js: -------------------------------------------------------------------------------- 1 | (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.es6Set = f()}})(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);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o= 0) fromIndex = floor(fromIndex); 212 | else fromIndex = toPosInt(this.length) - floor(abs(fromIndex)); 213 | 214 | for (i = fromIndex; i < l; ++i) { 215 | if (hasOwnProperty.call(this, i)) { 216 | val = this[i]; 217 | if (val !== val) return i; //jslint: ignore 218 | } 219 | } 220 | return -1; 221 | }; 222 | 223 | },{"../../number/to-pos-integer":15,"../../object/valid-value":34}],9:[function(require,module,exports){ 224 | 'use strict'; 225 | 226 | var toString = Object.prototype.toString 227 | 228 | , id = toString.call((function () { return arguments; }())); 229 | 230 | module.exports = function (x) { return (toString.call(x) === id); }; 231 | 232 | },{}],10:[function(require,module,exports){ 233 | 'use strict'; 234 | 235 | module.exports = new Function("return this")(); 236 | 237 | },{}],11:[function(require,module,exports){ 238 | 'use strict'; 239 | 240 | module.exports = require('./is-implemented')() 241 | ? Math.sign 242 | : require('./shim'); 243 | 244 | },{"./is-implemented":12,"./shim":13}],12:[function(require,module,exports){ 245 | 'use strict'; 246 | 247 | module.exports = function () { 248 | var sign = Math.sign; 249 | if (typeof sign !== 'function') return false; 250 | return ((sign(10) === 1) && (sign(-20) === -1)); 251 | }; 252 | 253 | },{}],13:[function(require,module,exports){ 254 | 'use strict'; 255 | 256 | module.exports = function (value) { 257 | value = Number(value); 258 | if (isNaN(value) || (value === 0)) return value; 259 | return (value > 0) ? 1 : -1; 260 | }; 261 | 262 | },{}],14:[function(require,module,exports){ 263 | 'use strict'; 264 | 265 | var sign = require('../math/sign') 266 | 267 | , abs = Math.abs, floor = Math.floor; 268 | 269 | module.exports = function (value) { 270 | if (isNaN(value)) return 0; 271 | value = Number(value); 272 | if ((value === 0) || !isFinite(value)) return value; 273 | return sign(value) * floor(abs(value)); 274 | }; 275 | 276 | },{"../math/sign":11}],15:[function(require,module,exports){ 277 | 'use strict'; 278 | 279 | var toInteger = require('./to-integer') 280 | 281 | , max = Math.max; 282 | 283 | module.exports = function (value) { return max(0, toInteger(value)); }; 284 | 285 | },{"./to-integer":14}],16:[function(require,module,exports){ 286 | // Internal method, used by iteration functions. 287 | // Calls a function for each key-value pair found in object 288 | // Optionally takes compareFn to iterate object in specific order 289 | 290 | 'use strict'; 291 | 292 | var callable = require('./valid-callable') 293 | , value = require('./valid-value') 294 | 295 | , bind = Function.prototype.bind, call = Function.prototype.call, keys = Object.keys 296 | , propertyIsEnumerable = Object.prototype.propertyIsEnumerable; 297 | 298 | module.exports = function (method, defVal) { 299 | return function (obj, cb/*, thisArg, compareFn*/) { 300 | var list, thisArg = arguments[2], compareFn = arguments[3]; 301 | obj = Object(value(obj)); 302 | callable(cb); 303 | 304 | list = keys(obj); 305 | if (compareFn) { 306 | list.sort((typeof compareFn === 'function') ? bind.call(compareFn, obj) : undefined); 307 | } 308 | if (typeof method !== 'function') method = list[method]; 309 | return call.call(method, list, function (key, index) { 310 | if (!propertyIsEnumerable.call(obj, key)) return defVal; 311 | return call.call(cb, thisArg, obj[key], key, obj, index); 312 | }); 313 | }; 314 | }; 315 | 316 | },{"./valid-callable":33,"./valid-value":34}],17:[function(require,module,exports){ 317 | 'use strict'; 318 | 319 | module.exports = require('./is-implemented')() 320 | ? Object.assign 321 | : require('./shim'); 322 | 323 | },{"./is-implemented":18,"./shim":19}],18:[function(require,module,exports){ 324 | 'use strict'; 325 | 326 | module.exports = function () { 327 | var assign = Object.assign, obj; 328 | if (typeof assign !== 'function') return false; 329 | obj = { foo: 'raz' }; 330 | assign(obj, { bar: 'dwa' }, { trzy: 'trzy' }); 331 | return (obj.foo + obj.bar + obj.trzy) === 'razdwatrzy'; 332 | }; 333 | 334 | },{}],19:[function(require,module,exports){ 335 | 'use strict'; 336 | 337 | var keys = require('../keys') 338 | , value = require('../valid-value') 339 | 340 | , max = Math.max; 341 | 342 | module.exports = function (dest, src/*, …srcn*/) { 343 | var error, i, l = max(arguments.length, 2), assign; 344 | dest = Object(value(dest)); 345 | assign = function (key) { 346 | try { dest[key] = src[key]; } catch (e) { 347 | if (!error) error = e; 348 | } 349 | }; 350 | for (i = 1; i < l; ++i) { 351 | src = arguments[i]; 352 | keys(src).forEach(assign); 353 | } 354 | if (error !== undefined) throw error; 355 | return dest; 356 | }; 357 | 358 | },{"../keys":25,"../valid-value":34}],20:[function(require,module,exports){ 359 | 'use strict'; 360 | 361 | var assign = require('./assign') 362 | , value = require('./valid-value'); 363 | 364 | module.exports = function (obj) { 365 | var copy = Object(value(obj)); 366 | if (copy !== obj) return copy; 367 | return assign({}, obj); 368 | }; 369 | 370 | },{"./assign":17,"./valid-value":34}],21:[function(require,module,exports){ 371 | // Workaround for http://code.google.com/p/v8/issues/detail?id=2804 372 | 373 | 'use strict'; 374 | 375 | var create = Object.create, shim; 376 | 377 | if (!require('./set-prototype-of/is-implemented')()) { 378 | shim = require('./set-prototype-of/shim'); 379 | } 380 | 381 | module.exports = (function () { 382 | var nullObject, props, desc; 383 | if (!shim) return create; 384 | if (shim.level !== 1) return create; 385 | 386 | nullObject = {}; 387 | props = {}; 388 | desc = { configurable: false, enumerable: false, writable: true, 389 | value: undefined }; 390 | Object.getOwnPropertyNames(Object.prototype).forEach(function (name) { 391 | if (name === '__proto__') { 392 | props[name] = { configurable: true, enumerable: false, writable: true, 393 | value: undefined }; 394 | return; 395 | } 396 | props[name] = desc; 397 | }); 398 | Object.defineProperties(nullObject, props); 399 | 400 | Object.defineProperty(shim, 'nullPolyfill', { configurable: false, 401 | enumerable: false, writable: false, value: nullObject }); 402 | 403 | return function (prototype, props) { 404 | return create((prototype === null) ? nullObject : prototype, props); 405 | }; 406 | }()); 407 | 408 | },{"./set-prototype-of/is-implemented":31,"./set-prototype-of/shim":32}],22:[function(require,module,exports){ 409 | 'use strict'; 410 | 411 | module.exports = require('./_iterate')('forEach'); 412 | 413 | },{"./_iterate":16}],23:[function(require,module,exports){ 414 | // Deprecated 415 | 416 | 'use strict'; 417 | 418 | module.exports = function (obj) { return typeof obj === 'function'; }; 419 | 420 | },{}],24:[function(require,module,exports){ 421 | 'use strict'; 422 | 423 | var map = { 'function': true, object: true }; 424 | 425 | module.exports = function (x) { 426 | return ((x != null) && map[typeof x]) || false; 427 | }; 428 | 429 | },{}],25:[function(require,module,exports){ 430 | 'use strict'; 431 | 432 | module.exports = require('./is-implemented')() 433 | ? Object.keys 434 | : require('./shim'); 435 | 436 | },{"./is-implemented":26,"./shim":27}],26:[function(require,module,exports){ 437 | 'use strict'; 438 | 439 | module.exports = function () { 440 | try { 441 | Object.keys('primitive'); 442 | return true; 443 | } catch (e) { return false; } 444 | }; 445 | 446 | },{}],27:[function(require,module,exports){ 447 | 'use strict'; 448 | 449 | var keys = Object.keys; 450 | 451 | module.exports = function (object) { 452 | return keys(object == null ? object : Object(object)); 453 | }; 454 | 455 | },{}],28:[function(require,module,exports){ 456 | 'use strict'; 457 | 458 | var callable = require('./valid-callable') 459 | , forEach = require('./for-each') 460 | 461 | , call = Function.prototype.call; 462 | 463 | module.exports = function (obj, cb/*, thisArg*/) { 464 | var o = {}, thisArg = arguments[2]; 465 | callable(cb); 466 | forEach(obj, function (value, key, obj, index) { 467 | o[key] = call.call(cb, thisArg, value, key, obj, index); 468 | }); 469 | return o; 470 | }; 471 | 472 | },{"./for-each":22,"./valid-callable":33}],29:[function(require,module,exports){ 473 | 'use strict'; 474 | 475 | var forEach = Array.prototype.forEach, create = Object.create; 476 | 477 | var process = function (src, obj) { 478 | var key; 479 | for (key in src) obj[key] = src[key]; 480 | }; 481 | 482 | module.exports = function (options/*, …options*/) { 483 | var result = create(null); 484 | forEach.call(arguments, function (options) { 485 | if (options == null) return; 486 | process(Object(options), result); 487 | }); 488 | return result; 489 | }; 490 | 491 | },{}],30:[function(require,module,exports){ 492 | 'use strict'; 493 | 494 | module.exports = require('./is-implemented')() 495 | ? Object.setPrototypeOf 496 | : require('./shim'); 497 | 498 | },{"./is-implemented":31,"./shim":32}],31:[function(require,module,exports){ 499 | 'use strict'; 500 | 501 | var create = Object.create, getPrototypeOf = Object.getPrototypeOf 502 | , x = {}; 503 | 504 | module.exports = function (/*customCreate*/) { 505 | var setPrototypeOf = Object.setPrototypeOf 506 | , customCreate = arguments[0] || create; 507 | if (typeof setPrototypeOf !== 'function') return false; 508 | return getPrototypeOf(setPrototypeOf(customCreate(null), x)) === x; 509 | }; 510 | 511 | },{}],32:[function(require,module,exports){ 512 | // Big thanks to @WebReflection for sorting this out 513 | // https://gist.github.com/WebReflection/5593554 514 | 515 | 'use strict'; 516 | 517 | var isObject = require('../is-object') 518 | , value = require('../valid-value') 519 | 520 | , isPrototypeOf = Object.prototype.isPrototypeOf 521 | , defineProperty = Object.defineProperty 522 | , nullDesc = { configurable: true, enumerable: false, writable: true, 523 | value: undefined } 524 | , validate; 525 | 526 | validate = function (obj, prototype) { 527 | value(obj); 528 | if ((prototype === null) || isObject(prototype)) return obj; 529 | throw new TypeError('Prototype must be null or an object'); 530 | }; 531 | 532 | module.exports = (function (status) { 533 | var fn, set; 534 | if (!status) return null; 535 | if (status.level === 2) { 536 | if (status.set) { 537 | set = status.set; 538 | fn = function (obj, prototype) { 539 | set.call(validate(obj, prototype), prototype); 540 | return obj; 541 | }; 542 | } else { 543 | fn = function (obj, prototype) { 544 | validate(obj, prototype).__proto__ = prototype; 545 | return obj; 546 | }; 547 | } 548 | } else { 549 | fn = function self(obj, prototype) { 550 | var isNullBase; 551 | validate(obj, prototype); 552 | isNullBase = isPrototypeOf.call(self.nullPolyfill, obj); 553 | if (isNullBase) delete self.nullPolyfill.__proto__; 554 | if (prototype === null) prototype = self.nullPolyfill; 555 | obj.__proto__ = prototype; 556 | if (isNullBase) defineProperty(self.nullPolyfill, '__proto__', nullDesc); 557 | return obj; 558 | }; 559 | } 560 | return Object.defineProperty(fn, 'level', { configurable: false, 561 | enumerable: false, writable: false, value: status.level }); 562 | }((function () { 563 | var x = Object.create(null), y = {}, set 564 | , desc = Object.getOwnPropertyDescriptor(Object.prototype, '__proto__'); 565 | 566 | if (desc) { 567 | try { 568 | set = desc.set; // Opera crashes at this point 569 | set.call(x, y); 570 | } catch (ignore) { } 571 | if (Object.getPrototypeOf(x) === y) return { set: set, level: 2 }; 572 | } 573 | 574 | x.__proto__ = y; 575 | if (Object.getPrototypeOf(x) === y) return { level: 2 }; 576 | 577 | x = {}; 578 | x.__proto__ = y; 579 | if (Object.getPrototypeOf(x) === y) return { level: 1 }; 580 | 581 | return false; 582 | }()))); 583 | 584 | require('../create'); 585 | 586 | },{"../create":21,"../is-object":24,"../valid-value":34}],33:[function(require,module,exports){ 587 | 'use strict'; 588 | 589 | module.exports = function (fn) { 590 | if (typeof fn !== 'function') throw new TypeError(fn + " is not a function"); 591 | return fn; 592 | }; 593 | 594 | },{}],34:[function(require,module,exports){ 595 | 'use strict'; 596 | 597 | module.exports = function (value) { 598 | if (value == null) throw new TypeError("Cannot use null or undefined"); 599 | return value; 600 | }; 601 | 602 | },{}],35:[function(require,module,exports){ 603 | 'use strict'; 604 | 605 | module.exports = require('./is-implemented')() 606 | ? String.prototype.contains 607 | : require('./shim'); 608 | 609 | },{"./is-implemented":36,"./shim":37}],36:[function(require,module,exports){ 610 | 'use strict'; 611 | 612 | var str = 'razdwatrzy'; 613 | 614 | module.exports = function () { 615 | if (typeof str.contains !== 'function') return false; 616 | return ((str.contains('dwa') === true) && (str.contains('foo') === false)); 617 | }; 618 | 619 | },{}],37:[function(require,module,exports){ 620 | 'use strict'; 621 | 622 | var indexOf = String.prototype.indexOf; 623 | 624 | module.exports = function (searchString/*, position*/) { 625 | return indexOf.call(this, searchString, arguments[1]) > -1; 626 | }; 627 | 628 | },{}],38:[function(require,module,exports){ 629 | 'use strict'; 630 | 631 | var toString = Object.prototype.toString 632 | 633 | , id = toString.call(''); 634 | 635 | module.exports = function (x) { 636 | return (typeof x === 'string') || (x && (typeof x === 'object') && 637 | ((x instanceof String) || (toString.call(x) === id))) || false; 638 | }; 639 | 640 | },{}],39:[function(require,module,exports){ 641 | 'use strict'; 642 | 643 | var setPrototypeOf = require('es5-ext/object/set-prototype-of') 644 | , contains = require('es5-ext/string/#/contains') 645 | , d = require('d') 646 | , Iterator = require('./') 647 | 648 | , defineProperty = Object.defineProperty 649 | , ArrayIterator; 650 | 651 | ArrayIterator = module.exports = function (arr, kind) { 652 | if (!(this instanceof ArrayIterator)) return new ArrayIterator(arr, kind); 653 | Iterator.call(this, arr); 654 | if (!kind) kind = 'value'; 655 | else if (contains.call(kind, 'key+value')) kind = 'key+value'; 656 | else if (contains.call(kind, 'key')) kind = 'key'; 657 | else kind = 'value'; 658 | defineProperty(this, '__kind__', d('', kind)); 659 | }; 660 | if (setPrototypeOf) setPrototypeOf(ArrayIterator, Iterator); 661 | 662 | ArrayIterator.prototype = Object.create(Iterator.prototype, { 663 | constructor: d(ArrayIterator), 664 | _resolve: d(function (i) { 665 | if (this.__kind__ === 'value') return this.__list__[i]; 666 | if (this.__kind__ === 'key+value') return [i, this.__list__[i]]; 667 | return i; 668 | }), 669 | toString: d(function () { return '[object Array Iterator]'; }) 670 | }); 671 | 672 | },{"./":42,"d":6,"es5-ext/object/set-prototype-of":30,"es5-ext/string/#/contains":35}],40:[function(require,module,exports){ 673 | 'use strict'; 674 | 675 | var isArguments = require('es5-ext/function/is-arguments') 676 | , callable = require('es5-ext/object/valid-callable') 677 | , isString = require('es5-ext/string/is-string') 678 | , get = require('./get') 679 | 680 | , isArray = Array.isArray, call = Function.prototype.call 681 | , some = Array.prototype.some; 682 | 683 | module.exports = function (iterable, cb/*, thisArg*/) { 684 | var mode, thisArg = arguments[2], result, doBreak, broken, i, l, char, code; 685 | if (isArray(iterable) || isArguments(iterable)) mode = 'array'; 686 | else if (isString(iterable)) mode = 'string'; 687 | else iterable = get(iterable); 688 | 689 | callable(cb); 690 | doBreak = function () { broken = true; }; 691 | if (mode === 'array') { 692 | some.call(iterable, function (value) { 693 | call.call(cb, thisArg, value, doBreak); 694 | if (broken) return true; 695 | }); 696 | return; 697 | } 698 | if (mode === 'string') { 699 | l = iterable.length; 700 | for (i = 0; i < l; ++i) { 701 | char = iterable[i]; 702 | if ((i + 1) < l) { 703 | code = char.charCodeAt(0); 704 | if ((code >= 0xD800) && (code <= 0xDBFF)) char += iterable[++i]; 705 | } 706 | call.call(cb, thisArg, char, doBreak); 707 | if (broken) break; 708 | } 709 | return; 710 | } 711 | result = iterable.next(); 712 | 713 | while (!result.done) { 714 | call.call(cb, thisArg, result.value, doBreak); 715 | if (broken) return; 716 | result = iterable.next(); 717 | } 718 | }; 719 | 720 | },{"./get":41,"es5-ext/function/is-arguments":9,"es5-ext/object/valid-callable":33,"es5-ext/string/is-string":38}],41:[function(require,module,exports){ 721 | 'use strict'; 722 | 723 | var isArguments = require('es5-ext/function/is-arguments') 724 | , isString = require('es5-ext/string/is-string') 725 | , ArrayIterator = require('./array') 726 | , StringIterator = require('./string') 727 | , iterable = require('./valid-iterable') 728 | , iteratorSymbol = require('es6-symbol').iterator; 729 | 730 | module.exports = function (obj) { 731 | if (typeof iterable(obj)[iteratorSymbol] === 'function') return obj[iteratorSymbol](); 732 | if (isArguments(obj)) return new ArrayIterator(obj); 733 | if (isString(obj)) return new StringIterator(obj); 734 | return new ArrayIterator(obj); 735 | }; 736 | 737 | },{"./array":39,"./string":44,"./valid-iterable":45,"es5-ext/function/is-arguments":9,"es5-ext/string/is-string":38,"es6-symbol":46}],42:[function(require,module,exports){ 738 | 'use strict'; 739 | 740 | var clear = require('es5-ext/array/#/clear') 741 | , assign = require('es5-ext/object/assign') 742 | , callable = require('es5-ext/object/valid-callable') 743 | , value = require('es5-ext/object/valid-value') 744 | , d = require('d') 745 | , autoBind = require('d/auto-bind') 746 | , Symbol = require('es6-symbol') 747 | 748 | , defineProperty = Object.defineProperty 749 | , defineProperties = Object.defineProperties 750 | , Iterator; 751 | 752 | module.exports = Iterator = function (list, context) { 753 | if (!(this instanceof Iterator)) return new Iterator(list, context); 754 | defineProperties(this, { 755 | __list__: d('w', value(list)), 756 | __context__: d('w', context), 757 | __nextIndex__: d('w', 0) 758 | }); 759 | if (!context) return; 760 | callable(context.on); 761 | context.on('_add', this._onAdd); 762 | context.on('_delete', this._onDelete); 763 | context.on('_clear', this._onClear); 764 | }; 765 | 766 | defineProperties(Iterator.prototype, assign({ 767 | constructor: d(Iterator), 768 | _next: d(function () { 769 | var i; 770 | if (!this.__list__) return; 771 | if (this.__redo__) { 772 | i = this.__redo__.shift(); 773 | if (i !== undefined) return i; 774 | } 775 | if (this.__nextIndex__ < this.__list__.length) return this.__nextIndex__++; 776 | this._unBind(); 777 | }), 778 | next: d(function () { return this._createResult(this._next()); }), 779 | _createResult: d(function (i) { 780 | if (i === undefined) return { done: true, value: undefined }; 781 | return { done: false, value: this._resolve(i) }; 782 | }), 783 | _resolve: d(function (i) { return this.__list__[i]; }), 784 | _unBind: d(function () { 785 | this.__list__ = null; 786 | delete this.__redo__; 787 | if (!this.__context__) return; 788 | this.__context__.off('_add', this._onAdd); 789 | this.__context__.off('_delete', this._onDelete); 790 | this.__context__.off('_clear', this._onClear); 791 | this.__context__ = null; 792 | }), 793 | toString: d(function () { return '[object Iterator]'; }) 794 | }, autoBind({ 795 | _onAdd: d(function (index) { 796 | if (index >= this.__nextIndex__) return; 797 | ++this.__nextIndex__; 798 | if (!this.__redo__) { 799 | defineProperty(this, '__redo__', d('c', [index])); 800 | return; 801 | } 802 | this.__redo__.forEach(function (redo, i) { 803 | if (redo >= index) this.__redo__[i] = ++redo; 804 | }, this); 805 | this.__redo__.push(index); 806 | }), 807 | _onDelete: d(function (index) { 808 | var i; 809 | if (index >= this.__nextIndex__) return; 810 | --this.__nextIndex__; 811 | if (!this.__redo__) return; 812 | i = this.__redo__.indexOf(index); 813 | if (i !== -1) this.__redo__.splice(i, 1); 814 | this.__redo__.forEach(function (redo, i) { 815 | if (redo > index) this.__redo__[i] = --redo; 816 | }, this); 817 | }), 818 | _onClear: d(function () { 819 | if (this.__redo__) clear.call(this.__redo__); 820 | this.__nextIndex__ = 0; 821 | }) 822 | }))); 823 | 824 | defineProperty(Iterator.prototype, Symbol.iterator, d(function () { 825 | return this; 826 | })); 827 | defineProperty(Iterator.prototype, Symbol.toStringTag, d('', 'Iterator')); 828 | 829 | },{"d":6,"d/auto-bind":5,"es5-ext/array/#/clear":7,"es5-ext/object/assign":17,"es5-ext/object/valid-callable":33,"es5-ext/object/valid-value":34,"es6-symbol":46}],43:[function(require,module,exports){ 830 | 'use strict'; 831 | 832 | var isArguments = require('es5-ext/function/is-arguments') 833 | , isString = require('es5-ext/string/is-string') 834 | , iteratorSymbol = require('es6-symbol').iterator 835 | 836 | , isArray = Array.isArray; 837 | 838 | module.exports = function (value) { 839 | if (value == null) return false; 840 | if (isArray(value)) return true; 841 | if (isString(value)) return true; 842 | if (isArguments(value)) return true; 843 | return (typeof value[iteratorSymbol] === 'function'); 844 | }; 845 | 846 | },{"es5-ext/function/is-arguments":9,"es5-ext/string/is-string":38,"es6-symbol":46}],44:[function(require,module,exports){ 847 | // Thanks @mathiasbynens 848 | // http://mathiasbynens.be/notes/javascript-unicode#iterating-over-symbols 849 | 850 | 'use strict'; 851 | 852 | var setPrototypeOf = require('es5-ext/object/set-prototype-of') 853 | , d = require('d') 854 | , Iterator = require('./') 855 | 856 | , defineProperty = Object.defineProperty 857 | , StringIterator; 858 | 859 | StringIterator = module.exports = function (str) { 860 | if (!(this instanceof StringIterator)) return new StringIterator(str); 861 | str = String(str); 862 | Iterator.call(this, str); 863 | defineProperty(this, '__length__', d('', str.length)); 864 | 865 | }; 866 | if (setPrototypeOf) setPrototypeOf(StringIterator, Iterator); 867 | 868 | StringIterator.prototype = Object.create(Iterator.prototype, { 869 | constructor: d(StringIterator), 870 | _next: d(function () { 871 | if (!this.__list__) return; 872 | if (this.__nextIndex__ < this.__length__) return this.__nextIndex__++; 873 | this._unBind(); 874 | }), 875 | _resolve: d(function (i) { 876 | var char = this.__list__[i], code; 877 | if (this.__nextIndex__ === this.__length__) return char; 878 | code = char.charCodeAt(0); 879 | if ((code >= 0xD800) && (code <= 0xDBFF)) return char + this.__list__[this.__nextIndex__++]; 880 | return char; 881 | }), 882 | toString: d(function () { return '[object String Iterator]'; }) 883 | }); 884 | 885 | },{"./":42,"d":6,"es5-ext/object/set-prototype-of":30}],45:[function(require,module,exports){ 886 | 'use strict'; 887 | 888 | var isIterable = require('./is-iterable'); 889 | 890 | module.exports = function (value) { 891 | if (!isIterable(value)) throw new TypeError(value + " is not iterable"); 892 | return value; 893 | }; 894 | 895 | },{"./is-iterable":43}],46:[function(require,module,exports){ 896 | 'use strict'; 897 | 898 | module.exports = require('./is-implemented')() ? Symbol : require('./polyfill'); 899 | 900 | },{"./is-implemented":47,"./polyfill":49}],47:[function(require,module,exports){ 901 | 'use strict'; 902 | 903 | var validTypes = { object: true, symbol: true }; 904 | 905 | module.exports = function () { 906 | var symbol; 907 | if (typeof Symbol !== 'function') return false; 908 | symbol = Symbol('test symbol'); 909 | try { String(symbol); } catch (e) { return false; } 910 | 911 | // Return 'true' also for polyfills 912 | if (!validTypes[typeof Symbol.iterator]) return false; 913 | if (!validTypes[typeof Symbol.toPrimitive]) return false; 914 | if (!validTypes[typeof Symbol.toStringTag]) return false; 915 | 916 | return true; 917 | }; 918 | 919 | },{}],48:[function(require,module,exports){ 920 | 'use strict'; 921 | 922 | module.exports = function (x) { 923 | if (!x) return false; 924 | if (typeof x === 'symbol') return true; 925 | if (!x.constructor) return false; 926 | if (x.constructor.name !== 'Symbol') return false; 927 | return (x[x.constructor.toStringTag] === 'Symbol'); 928 | }; 929 | 930 | },{}],49:[function(require,module,exports){ 931 | // ES2015 Symbol polyfill for environments that do not (or partially) support it 932 | 933 | 'use strict'; 934 | 935 | var d = require('d') 936 | , validateSymbol = require('./validate-symbol') 937 | 938 | , create = Object.create, defineProperties = Object.defineProperties 939 | , defineProperty = Object.defineProperty, objPrototype = Object.prototype 940 | , NativeSymbol, SymbolPolyfill, HiddenSymbol, globalSymbols = create(null) 941 | , isNativeSafe; 942 | 943 | if (typeof Symbol === 'function') { 944 | NativeSymbol = Symbol; 945 | try { 946 | String(NativeSymbol()); 947 | isNativeSafe = true; 948 | } catch (ignore) {} 949 | } 950 | 951 | var generateName = (function () { 952 | var created = create(null); 953 | return function (desc) { 954 | var postfix = 0, name, ie11BugWorkaround; 955 | while (created[desc + (postfix || '')]) ++postfix; 956 | desc += (postfix || ''); 957 | created[desc] = true; 958 | name = '@@' + desc; 959 | defineProperty(objPrototype, name, d.gs(null, function (value) { 960 | // For IE11 issue see: 961 | // https://connect.microsoft.com/IE/feedbackdetail/view/1928508/ 962 | // ie11-broken-getters-on-dom-objects 963 | // https://github.com/medikoo/es6-symbol/issues/12 964 | if (ie11BugWorkaround) return; 965 | ie11BugWorkaround = true; 966 | defineProperty(this, name, d(value)); 967 | ie11BugWorkaround = false; 968 | })); 969 | return name; 970 | }; 971 | }()); 972 | 973 | // Internal constructor (not one exposed) for creating Symbol instances. 974 | // This one is used to ensure that `someSymbol instanceof Symbol` always return false 975 | HiddenSymbol = function Symbol(description) { 976 | if (this instanceof HiddenSymbol) throw new TypeError('Symbol is not a constructor'); 977 | return SymbolPolyfill(description); 978 | }; 979 | 980 | // Exposed `Symbol` constructor 981 | // (returns instances of HiddenSymbol) 982 | module.exports = SymbolPolyfill = function Symbol(description) { 983 | var symbol; 984 | if (this instanceof Symbol) throw new TypeError('Symbol is not a constructor'); 985 | if (isNativeSafe) return NativeSymbol(description); 986 | symbol = create(HiddenSymbol.prototype); 987 | description = (description === undefined ? '' : String(description)); 988 | return defineProperties(symbol, { 989 | __description__: d('', description), 990 | __name__: d('', generateName(description)) 991 | }); 992 | }; 993 | defineProperties(SymbolPolyfill, { 994 | for: d(function (key) { 995 | if (globalSymbols[key]) return globalSymbols[key]; 996 | return (globalSymbols[key] = SymbolPolyfill(String(key))); 997 | }), 998 | keyFor: d(function (s) { 999 | var key; 1000 | validateSymbol(s); 1001 | for (key in globalSymbols) if (globalSymbols[key] === s) return key; 1002 | }), 1003 | 1004 | // To ensure proper interoperability with other native functions (e.g. Array.from) 1005 | // fallback to eventual native implementation of given symbol 1006 | hasInstance: d('', (NativeSymbol && NativeSymbol.hasInstance) || SymbolPolyfill('hasInstance')), 1007 | isConcatSpreadable: d('', (NativeSymbol && NativeSymbol.isConcatSpreadable) || 1008 | SymbolPolyfill('isConcatSpreadable')), 1009 | iterator: d('', (NativeSymbol && NativeSymbol.iterator) || SymbolPolyfill('iterator')), 1010 | match: d('', (NativeSymbol && NativeSymbol.match) || SymbolPolyfill('match')), 1011 | replace: d('', (NativeSymbol && NativeSymbol.replace) || SymbolPolyfill('replace')), 1012 | search: d('', (NativeSymbol && NativeSymbol.search) || SymbolPolyfill('search')), 1013 | species: d('', (NativeSymbol && NativeSymbol.species) || SymbolPolyfill('species')), 1014 | split: d('', (NativeSymbol && NativeSymbol.split) || SymbolPolyfill('split')), 1015 | toPrimitive: d('', (NativeSymbol && NativeSymbol.toPrimitive) || SymbolPolyfill('toPrimitive')), 1016 | toStringTag: d('', (NativeSymbol && NativeSymbol.toStringTag) || SymbolPolyfill('toStringTag')), 1017 | unscopables: d('', (NativeSymbol && NativeSymbol.unscopables) || SymbolPolyfill('unscopables')) 1018 | }); 1019 | 1020 | // Internal tweaks for real symbol producer 1021 | defineProperties(HiddenSymbol.prototype, { 1022 | constructor: d(SymbolPolyfill), 1023 | toString: d('', function () { return this.__name__; }) 1024 | }); 1025 | 1026 | // Proper implementation of methods exposed on Symbol.prototype 1027 | // They won't be accessible on produced symbol instances as they derive from HiddenSymbol.prototype 1028 | defineProperties(SymbolPolyfill.prototype, { 1029 | toString: d(function () { return 'Symbol (' + validateSymbol(this).__description__ + ')'; }), 1030 | valueOf: d(function () { return validateSymbol(this); }) 1031 | }); 1032 | defineProperty(SymbolPolyfill.prototype, SymbolPolyfill.toPrimitive, d('', function () { 1033 | var symbol = validateSymbol(this); 1034 | if (typeof symbol === 'symbol') return symbol; 1035 | return symbol.toString(); 1036 | })); 1037 | defineProperty(SymbolPolyfill.prototype, SymbolPolyfill.toStringTag, d('c', 'Symbol')); 1038 | 1039 | // Proper implementaton of toPrimitive and toStringTag for returned symbol instances 1040 | defineProperty(HiddenSymbol.prototype, SymbolPolyfill.toStringTag, 1041 | d('c', SymbolPolyfill.prototype[SymbolPolyfill.toStringTag])); 1042 | 1043 | // Note: It's important to define `toPrimitive` as last one, as some implementations 1044 | // implement `toPrimitive` natively without implementing `toStringTag` (or other specified symbols) 1045 | // And that may invoke error in definition flow: 1046 | // See: https://github.com/medikoo/es6-symbol/issues/13#issuecomment-164146149 1047 | defineProperty(HiddenSymbol.prototype, SymbolPolyfill.toPrimitive, 1048 | d('c', SymbolPolyfill.prototype[SymbolPolyfill.toPrimitive])); 1049 | 1050 | },{"./validate-symbol":50,"d":6}],50:[function(require,module,exports){ 1051 | 'use strict'; 1052 | 1053 | var isSymbol = require('./is-symbol'); 1054 | 1055 | module.exports = function (value) { 1056 | if (!isSymbol(value)) throw new TypeError(value + " is not a symbol"); 1057 | return value; 1058 | }; 1059 | 1060 | },{"./is-symbol":48}],51:[function(require,module,exports){ 1061 | 'use strict'; 1062 | 1063 | var d = require('d') 1064 | , callable = require('es5-ext/object/valid-callable') 1065 | 1066 | , apply = Function.prototype.apply, call = Function.prototype.call 1067 | , create = Object.create, defineProperty = Object.defineProperty 1068 | , defineProperties = Object.defineProperties 1069 | , hasOwnProperty = Object.prototype.hasOwnProperty 1070 | , descriptor = { configurable: true, enumerable: false, writable: true } 1071 | 1072 | , on, once, off, emit, methods, descriptors, base; 1073 | 1074 | on = function (type, listener) { 1075 | var data; 1076 | 1077 | callable(listener); 1078 | 1079 | if (!hasOwnProperty.call(this, '__ee__')) { 1080 | data = descriptor.value = create(null); 1081 | defineProperty(this, '__ee__', descriptor); 1082 | descriptor.value = null; 1083 | } else { 1084 | data = this.__ee__; 1085 | } 1086 | if (!data[type]) data[type] = listener; 1087 | else if (typeof data[type] === 'object') data[type].push(listener); 1088 | else data[type] = [data[type], listener]; 1089 | 1090 | return this; 1091 | }; 1092 | 1093 | once = function (type, listener) { 1094 | var once, self; 1095 | 1096 | callable(listener); 1097 | self = this; 1098 | on.call(this, type, once = function () { 1099 | off.call(self, type, once); 1100 | apply.call(listener, this, arguments); 1101 | }); 1102 | 1103 | once.__eeOnceListener__ = listener; 1104 | return this; 1105 | }; 1106 | 1107 | off = function (type, listener) { 1108 | var data, listeners, candidate, i; 1109 | 1110 | callable(listener); 1111 | 1112 | if (!hasOwnProperty.call(this, '__ee__')) return this; 1113 | data = this.__ee__; 1114 | if (!data[type]) return this; 1115 | listeners = data[type]; 1116 | 1117 | if (typeof listeners === 'object') { 1118 | for (i = 0; (candidate = listeners[i]); ++i) { 1119 | if ((candidate === listener) || 1120 | (candidate.__eeOnceListener__ === listener)) { 1121 | if (listeners.length === 2) data[type] = listeners[i ? 0 : 1]; 1122 | else listeners.splice(i, 1); 1123 | } 1124 | } 1125 | } else { 1126 | if ((listeners === listener) || 1127 | (listeners.__eeOnceListener__ === listener)) { 1128 | delete data[type]; 1129 | } 1130 | } 1131 | 1132 | return this; 1133 | }; 1134 | 1135 | emit = function (type) { 1136 | var i, l, listener, listeners, args; 1137 | 1138 | if (!hasOwnProperty.call(this, '__ee__')) return; 1139 | listeners = this.__ee__[type]; 1140 | if (!listeners) return; 1141 | 1142 | if (typeof listeners === 'object') { 1143 | l = arguments.length; 1144 | args = new Array(l - 1); 1145 | for (i = 1; i < l; ++i) args[i - 1] = arguments[i]; 1146 | 1147 | listeners = listeners.slice(); 1148 | for (i = 0; (listener = listeners[i]); ++i) { 1149 | apply.call(listener, this, args); 1150 | } 1151 | } else { 1152 | switch (arguments.length) { 1153 | case 1: 1154 | call.call(listeners, this); 1155 | break; 1156 | case 2: 1157 | call.call(listeners, this, arguments[1]); 1158 | break; 1159 | case 3: 1160 | call.call(listeners, this, arguments[1], arguments[2]); 1161 | break; 1162 | default: 1163 | l = arguments.length; 1164 | args = new Array(l - 1); 1165 | for (i = 1; i < l; ++i) { 1166 | args[i - 1] = arguments[i]; 1167 | } 1168 | apply.call(listeners, this, args); 1169 | } 1170 | } 1171 | }; 1172 | 1173 | methods = { 1174 | on: on, 1175 | once: once, 1176 | off: off, 1177 | emit: emit 1178 | }; 1179 | 1180 | descriptors = { 1181 | on: d(on), 1182 | once: d(once), 1183 | off: d(off), 1184 | emit: d(emit) 1185 | }; 1186 | 1187 | base = defineProperties({}, descriptors); 1188 | 1189 | module.exports = exports = function (o) { 1190 | return (o == null) ? create(base) : defineProperties(Object(o), descriptors); 1191 | }; 1192 | exports.methods = methods; 1193 | 1194 | },{"d":6,"es5-ext/object/valid-callable":33}],52:[function(require,module,exports){ 1195 | 'use strict'; 1196 | 1197 | var clear = require('es5-ext/array/#/clear') 1198 | , eIndexOf = require('es5-ext/array/#/e-index-of') 1199 | , setPrototypeOf = require('es5-ext/object/set-prototype-of') 1200 | , callable = require('es5-ext/object/valid-callable') 1201 | , d = require('d') 1202 | , ee = require('event-emitter') 1203 | , Symbol = require('es6-symbol') 1204 | , iterator = require('es6-iterator/valid-iterable') 1205 | , forOf = require('es6-iterator/for-of') 1206 | , Iterator = require('./lib/iterator') 1207 | , isNative = require('./is-native-implemented') 1208 | 1209 | , call = Function.prototype.call 1210 | , defineProperty = Object.defineProperty, getPrototypeOf = Object.getPrototypeOf 1211 | , SetPoly, getValues, NativeSet; 1212 | 1213 | if (isNative) NativeSet = Set; 1214 | 1215 | module.exports = SetPoly = function Set(/*iterable*/) { 1216 | var iterable = arguments[0], self; 1217 | if (!(this instanceof SetPoly)) throw new TypeError('Constructor requires \'new\''); 1218 | if (isNative && setPrototypeOf) self = setPrototypeOf(new NativeSet(), getPrototypeOf(this)); 1219 | else self = this; 1220 | if (iterable != null) iterator(iterable); 1221 | defineProperty(self, '__setData__', d('c', [])); 1222 | if (!iterable) return self; 1223 | forOf(iterable, function (value) { 1224 | if (eIndexOf.call(this, value) !== -1) return; 1225 | this.push(value); 1226 | }, self.__setData__); 1227 | return self; 1228 | }; 1229 | 1230 | if (isNative) { 1231 | if (setPrototypeOf) setPrototypeOf(SetPoly, NativeSet); 1232 | SetPoly.prototype = Object.create(NativeSet.prototype, { constructor: d(SetPoly) }); 1233 | } 1234 | 1235 | ee(Object.defineProperties(SetPoly.prototype, { 1236 | add: d(function (value) { 1237 | if (this.has(value)) return this; 1238 | this.emit('_add', this.__setData__.push(value) - 1, value); 1239 | return this; 1240 | }), 1241 | clear: d(function () { 1242 | if (!this.__setData__.length) return; 1243 | clear.call(this.__setData__); 1244 | this.emit('_clear'); 1245 | }), 1246 | delete: d(function (value) { 1247 | var index = eIndexOf.call(this.__setData__, value); 1248 | if (index === -1) return false; 1249 | this.__setData__.splice(index, 1); 1250 | this.emit('_delete', index, value); 1251 | return true; 1252 | }), 1253 | entries: d(function () { return new Iterator(this, 'key+value'); }), 1254 | forEach: d(function (cb/*, thisArg*/) { 1255 | var thisArg = arguments[1], iterator, result, value; 1256 | callable(cb); 1257 | iterator = this.values(); 1258 | result = iterator._next(); 1259 | while (result !== undefined) { 1260 | value = iterator._resolve(result); 1261 | call.call(cb, thisArg, value, value, this); 1262 | result = iterator._next(); 1263 | } 1264 | }), 1265 | has: d(function (value) { 1266 | return (eIndexOf.call(this.__setData__, value) !== -1); 1267 | }), 1268 | keys: d(getValues = function () { return this.values(); }), 1269 | size: d.gs(function () { return this.__setData__.length; }), 1270 | values: d(function () { return new Iterator(this); }), 1271 | toString: d(function () { return '[object Set]'; }) 1272 | })); 1273 | defineProperty(SetPoly.prototype, Symbol.iterator, d(getValues)); 1274 | defineProperty(SetPoly.prototype, Symbol.toStringTag, d('c', 'Set')); 1275 | 1276 | },{"./is-native-implemented":3,"./lib/iterator":4,"d":6,"es5-ext/array/#/clear":7,"es5-ext/array/#/e-index-of":8,"es5-ext/object/set-prototype-of":30,"es5-ext/object/valid-callable":33,"es6-iterator/for-of":40,"es6-iterator/valid-iterable":45,"es6-symbol":46,"event-emitter":51}]},{},[1])(1) 1277 | }); --------------------------------------------------------------------------------