* @internal
(
keyOrStateOrProjectState: Partial<State> | ProjectStateFn<State> | Key,
stateOrSliceProjectFn?: ProjectValueFn<State, Key>,
)
| 329 | * @internal |
| 330 | */ |
| 331 | set<Key extends keyof State>( |
| 332 | keyOrStateOrProjectState: Partial<State> | ProjectStateFn<State> | Key, |
| 333 | stateOrSliceProjectFn?: ProjectValueFn<State, Key>, |
| 334 | ): void { |
| 335 | if ( |
| 336 | typeof keyOrStateOrProjectState === 'object' && |
| 337 | stateOrSliceProjectFn === undefined |
| 338 | ) { |
| 339 | this.accumulator.nextSlice(keyOrStateOrProjectState); |
| 340 | return; |
| 341 | } |
| 342 | |
| 343 | if ( |
| 344 | typeof keyOrStateOrProjectState === 'function' && |
| 345 | stateOrSliceProjectFn === undefined |
| 346 | ) { |
| 347 | this.accumulator.nextSlice( |
| 348 | keyOrStateOrProjectState(this.accumulator.state), |
| 349 | ); |
| 350 | return; |
| 351 | } |
| 352 | |
| 353 | if ( |
| 354 | isKeyOf<State>(keyOrStateOrProjectState) && |
| 355 | typeof stateOrSliceProjectFn === 'function' |
| 356 | ) { |
| 357 | const state: Partial<State> = {}; |
| 358 | state[keyOrStateOrProjectState] = stateOrSliceProjectFn( |
| 359 | this.accumulator.state, |
| 360 | ); |
| 361 | this.accumulator.nextSlice(state); |
| 362 | return; |
| 363 | } |
| 364 | |
| 365 | throw new Error('wrong params passed to set'); |
| 366 | } |
| 367 | |
| 368 | /** |
| 369 | * @description |