Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Partial Laravel Package

react/partial

Lightweight partial function application for PHP. Pre-fill (bind) some arguments of any callable and get back a new callable with fewer required params—handy for async callbacks and event handlers where you need to pass extra context without verbose closures.

View on GitHub
Deep Wiki
Context7

Partial function application.

Frequently asked questions about Partial
How does react/partial help with Laravel + ReactPHP async callbacks?
It lets you pre-fill arguments in async callbacks (e.g., WebSocket handlers or HTTP routes) without wrapping everything in closures. For example, bind a user ID to a callback: `$handle = bind([UserHandler::class, 'process'], $user);`—cleaner than `use ($user)` in closures.
Can I use react/partial in Laravel middleware without ReactPHP?
Yes! It works in synchronous middleware too. Bind request/response contexts to middleware logic (e.g., `$middleware = bind([AuthMiddleware::class, 'handle'], $user)`) to avoid manual closures or `$this->app->call()` wrappers.
What Laravel versions and PHP requirements does react/partial support?
No Laravel-specific dependencies—just PHP 7.1+. Works with any Laravel 5.5+ app, but async use cases (e.g., ReactPHP) require separate setup (e.g., `spatie/react` or `react/laravel`).
How do I install react/partial in a Laravel project?
Run `composer require react/partial:^2.0`—no Laravel-specific commands. For async use, pair it with ReactPHP (e.g., `react/http` for HTTP servers) via `spatie/react` or `react/laravel`.
Does react/partial work with Eloquent models or controllers?
Limited value for pure Eloquent/controllers. It shines in async contexts (e.g., custom queue workers with ReactPHP) or when replacing spaghetti closures in event listeners. For controllers, consider Laravel’s `app()->call()` instead.
How do I debug partially applied functions in Laravel?
Prefix bound functions (e.g., `$processOrderWithUser = bind(...)`) and log bound args at creation (e.g., `Logger::debug('Bound user ID:', $user->id)`). Stack traces may obscure origin—use naming conventions to trace back.
Is react/partial safe for production? Any memory leak risks?
Yes, it’s production-ready with no runtime dependencies. Test for memory leaks in long-running async contexts (e.g., WebSocket servers) by verifying closures don’t persist unintentionally. ReactPHP’s error handlers should propagate errors correctly.
Can react/partial replace Laravel’s Closure::bindTo() or DI containers?
For async callbacks or functional patterns, yes—it’s more concise. For dependency injection, stick with Laravel’s container. Example: Replace `$this->app->call([User::class, 'method'], $args)` with `bind([User::class, 'method'], $prefilledArg)`.
How do I test code using react/partial in PHPUnit?
Mock bound functions like closures but with explicit args. Example: `$bound = bind([$mock, 'handle'], $user); $this->expects($mock->handle($contents))->with($user)->once();`—verify both bound and dynamic args.
What’s a better alternative if I’m not using ReactPHP?
For synchronous Laravel, use `Closure::bindTo()` or Laravel’s `app()->call()`. For async, consider `amp/async-function` (Amp) or `spatie/react` (ReactPHP). `react/partial` excels only in async/event-driven code where argument binding is repetitive.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours