You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be nice to add a set method to the accumulator that, unlike update, will only change the value if it is not set.
This could simplify many logical scenarios where something is being extended using apply_filters, but the update only needs to be made if nothing else is currently set.
For example:
// GIVEN$item = newclass{
use With_Subject;
publicfunctionget_user_photo($id){
return$this->apply_filters( 'user:photo', newAccumulator( [
'default' => null, // Default value is null'state' => [ 'id' => $id ],
'valid_callback' => fn ( $value ) => is_string( $value ),
] ) );
}
}
// NEW$item->attach( 'user:photo', newObserver( 'key', [
'update' => function ( $instance, Accumulator$accumulator ) {
// Only sets if the state hasn't already been set.$accumulator->set( Integrations\User::class );
},
] ) );
// OLD$item->attach( 'user:photo', newObserver( 'key', [
'update' => function ( $instance, Accumulator$accumulator ) {
if($accumulator->get_state() === null) $accumulator->update( Integrations\User::class );
},
] ) );
The text was updated successfully, but these errors were encountered:
It would be nice to add a
set
method to the accumulator that, unlike update, will only change the value if it is not set.This could simplify many logical scenarios where something is being extended using
apply_filters
, but the update only needs to be made if nothing else is currently set.For example:
The text was updated successfully, but these errors were encountered: