code: public function onUpdate(ResourceEventInterface $event)
      {
          $shipment = $this->getShipmentFromEvent($event);
  
          $this->preventForbiddenChange($shipment);
  
          // Generate number and key
          $changed = $this->generateNumber($shipment);
  
          $stateChanged = $this->persistenceHelper->isChanged($shipment, 'state');
          if ($stateChanged) {
              $changed |= $this->handleCompletedState($shipment);
          }
  
          if ($changed) {
              $this->persistenceHelper->persistAndRecompute($shipment);
          }
  
          if ($stateChanged) {
              $stateCs = $this->persistenceHelper->getChangeSet($shipment, 'state');
  
              // If shipment state has changed from non stockable to stockable
              if (ShipmentStates::hasChangedToStockable($stateCs)) {
                  // For each shipment item
                  foreach ($shipment->getItems() as $item) {
                      // If not scheduled for insert
                      if (!$this->persistenceHelper->isScheduledForInsert($item)) {
                          // Credit sale item stock units shipped quantity through assignments
                          $this->stockUnitAssigner->assignShipmentItem($item);
                      }
                  }
              }
              // Else if shipment state has changed from stockable to non stockable
              elseif (ShipmentStates::hasChangedFromStockable($stateCs)) {
                  // For each shipment item
                  foreach ($shipment->getItems() as $item) {
                      // If not scheduled for remove
                      if (!$this->persistenceHelper->isScheduledForRemove($item)) {
                          // Debit sale item stock units shipped quantity through assignments
                          $this->stockUnitAssigner->detachShipmentItem($item);
                      }
                  }
              }
          }
  
          $this->invoiceSynchronizer->synchronize($shipment);
  
          if ($changed || $stateChanged) {
              $this->scheduleSaleContentChangeEvent($this->getSaleFromShipment($shipment));
          }
      }
docs: Update event handler.
  
  @param ResourceEventInterface $event