-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: New Methods for Matreshka.Array: fill and copyWithin
- v2.4.18
- v2.4.17
- v2.4.16
- v2.4.15
- v2.4.14
- v2.4.13
- v2.4.12
- v2.4.11
- v2.4.10
- v2.4.9
- v2.4.8
- v2.4.7
- v2.4.6
- v2.4.5
- v2.4.4
- v2.4.3
- v2.4.2
- v2.4.0
- v2.3.1
- v2.3.0
- v2.2.0
- v2.1.1
- v2.1.0
- v2.0.2
- v2.0.1
- v2.0.0
- v2.0.0-beta.6
- v2.0.0-beta.5
- v2.0.0-beta.4
- v2.0.0-beta.3
- v2.0.0-beta.2
- v2.0.0-beta.1
- v2.0.0-beta.0
- v2.0.0-alpha.14
- v2.0.0-alpha.13
- v2.0.0-alpha.12
- v2.0.0-alpha.11
- v2.0.0-alpha.10
- v2.0.0-alpha.9
- v2.0.0-alpha.8
Showing
6 changed files
with
149 additions
and
2 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
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import apply from '../../_helpers/apply'; | ||
import reportModified from '../_reportmodified'; | ||
import matreshkaError from '../../_helpers/matreshkaerror'; | ||
|
||
export default function createCopyWithin(hasOptions) { | ||
return function copyWithin() { | ||
const originalCopyWithin = Array.prototype.copyWithin; | ||
|
||
if(!originalCopyWithin) { | ||
throw matreshkaError('array:nonexistent_method', { method: 'copyWithin' }); | ||
} | ||
// +hasOptions is converted to 0 or 1 depending on its value (false/true) | ||
const argsLength = arguments.length - +hasOptions; | ||
const args = Array(argsLength); | ||
const givenEventOptions = hasOptions ? arguments[arguments.length - 1] : null; | ||
|
||
for (let i = 0; i < argsLength; i++) { | ||
args[i] = arguments[i]; | ||
} | ||
|
||
apply(originalCopyWithin, this, args); | ||
|
||
const eventOptions = { | ||
method: 'copyWithin', | ||
self: this, | ||
added: [], | ||
removed: [] | ||
}; | ||
|
||
// extend event options by custom event options if they are given | ||
if (hasOptions) { | ||
if (givenEventOptions && typeof givenEventOptions === 'object') { | ||
nofn.assign(eventOptions, givenEventOptions); | ||
} | ||
} | ||
|
||
reportModified(this, eventOptions); | ||
|
||
return this; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import apply from '../../_helpers/apply'; | ||
import reportModified from '../_reportmodified'; | ||
import matreshkaError from '../../_helpers/matreshkaerror'; | ||
|
||
export default function createFill(hasOptions) { | ||
return function fill(value) { | ||
const originalFill = Array.prototype.fill; | ||
|
||
if(!originalFill) { | ||
throw matreshkaError('array:nonexistent_method', { method: 'fill' }); | ||
} | ||
// +hasOptions is converted to 0 or 1 depending on its value (false/true) | ||
const argsLength = arguments.length - +hasOptions; | ||
const args = Array(argsLength); | ||
const givenEventOptions = hasOptions ? arguments[arguments.length - 1] : null; | ||
|
||
for (let i = 0; i < argsLength; i++) { | ||
args[i] = arguments[i]; | ||
} | ||
|
||
apply(originalFill, this, args); | ||
|
||
const eventOptions = { | ||
method: 'fill', | ||
self: this, | ||
added: [value], | ||
removed: [] | ||
}; | ||
|
||
// extend event options by custom event options if they are given | ||
if (hasOptions) { | ||
if (givenEventOptions && typeof givenEventOptions === 'object') { | ||
nofn.assign(eventOptions, givenEventOptions); | ||
} | ||
} | ||
|
||
reportModified(this, eventOptions); | ||
|
||
return this; | ||
} | ||
} |
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
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