Releases: haltcase/babel-plugin-partial-application
v1.6.1
v1.6.0
All new features have been added to the online playground!
This release adds positional placeholders! Sometimes called swizzle or rearg,
you can partially apply arguments in a different order than the function normally
accepts, or use a single argument multiple times.
Let's say you want to reorder the arguments of lodash.get()
, which normally has
a signature of object, path, defaultValue
, to path, defaultValue, object
:
// forget that lodash/fp even exists for a second :)
import { get } from 'lodash'
// reorder the arguments so the data is accepted last
const getFunctional = get(_`3`, _`1`, _`2`)
getFunctional('color', 'blue', { color: 'green' })
// -> 'green'
You can also use positional placeholders to reuse a single argument, for example
to create a function checking if something is equal to itself ( NaN
never is ):
const isSameThing = _`1` === _`1`
isSameThing('yes!')
// -> true
isSameThing(NaN)
// -> false
Features
- add positional placeholder syntax (dbc9f9f)
Bug fixes
- fix mid-chain properties in applied call arguments being compiled if they look like a placeholder (6bc3d01)
- track custom tokens per file to prevent leaks into others, breaking their placeholders (2e39c99)
Playground
The playground got a few UI & UX improvements:
- 'send to editor' buttons on all JS code blocks for easily trying out the examples
- a 'go to top' button in the readme when you've scrolled down
- better URL handling (used for linking to the readme and specific sections of it)
v1.5.0
All new features have been added to the online playground!
The headline for this release is default parameter support:
const greet = name => console.log(`Hello, ${name}!`)
const sayHelloToPerson = greet(_.name = 'world')
sayHelloToPerson({ name: 'Arlene' })
// -> Hello, Arlene!
sayHelloToPerson({ /* nameless */ })
// -> Hello, world!
This is supported only as arguments in function calls, for basic & object placeholders.
Features
- add default parameter capability for basic placeholders & object placeholders (a7640ba)
Bug fixes
- fix template literal compilation so that member expression properties are ignored, ie.
_._
is not two placeholders and now compiles to_obj._
(e3a578b)
v1.4.0
All new features have been added to the online playground!
This release improves spread placeholders by supporting them in member expressions
and fixes an issue that occurs when passing an object placeholder as an argument
to an object placeholder call ( along with further nesting into binary expressions ).
In prior releases, this was the situation:
// worked fine
blah.foo(..._)
// 'Placeholder spread is unsupported outside call expressions.'
_.foo(..._)
... but this will now compile just fine to:
(_obj, ..._spr) => {
return _obj.foo(..._spr)
}
The other fixes are for these situations:
_.foo(_.bar)
_.foo(_.baz())
_.foo(_.name === 'Dude')
... which would all fail with a container is falsy
error. Now they work as expected.
Features
- support spread placeholders in member calls like
_.foo(..._)
(b766359)
Bug fixes
- object placeholders and some previously busted binary expressions now work correctly as arguments to object placeholder member calls (
_.foo(_.bar)
) (4aaadb5)
v1.3.0
v1.2.0
All new features have been added to the online playground!
This release adds the pretty cool feature of setting a custom placeholder by import
ing or require
ing the plugin, but this is removed at compile time so no runtime dependency is required.
import $ from 'babel-plugin-partial-application'
const log = console.log($, $.foo)
log(42, { foo: 'bar' })
// -> 42 bar
This should keep linters off your back without declaring a global, and should help out TypeScript & Flow users also.