Search in sources :

Example 1 with NodeDetachChange

use of com.vaadin.flow.internal.change.NodeDetachChange in project flow by vaadin.

the class StateNode method collectChanges.

/**
 * Collects all changes made to this node since the last time
 * {@link #collectChanges(Consumer)} has been called. If the node is
 * recently attached, then the reported changes will be relative to a newly
 * created node.
 *
 * @param collector
 *            a consumer accepting node changes
 */
public void collectChanges(Consumer<NodeChange> collector) {
    boolean isAttached = isAttached();
    if (isAttached != wasAttached) {
        if (isAttached) {
            collector.accept(new NodeAttachChange(this));
            // Make all changes show up as if the node was recently attached
            clearChanges();
            getFeatures().values().forEach(NodeFeature::generateChangesFromEmpty);
        } else {
            collector.accept(new NodeDetachChange(this));
        }
        wasAttached = isAttached;
    }
    if (!isAttached()) {
        return;
    }
    if (isInactive()) {
        if (!isInactiveSelf) {
            /*
                 * We are here if: the node itself is not inactive but it has
                 * some ascendant which is inactive.
                 *
                 * In this case we send only some subset of changes (not from
                 * all the features). But we should send changes for all
                 * remaining features. Normally it automatically happens if the
                 * node becomes "visible". But if it was visible with some
                 * invisible parent then only the parent becomes dirty (when
                 * it's set visible) and this child will never participate in
                 * collection of changes since it's not marked as dirty.
                 *
                 * So here such node (which is active itself but its ascendant
                 * is inactive) we mark as dirty again to be able to collect its
                 * changes later on when its ascendant becomes active.
                 */
            getOwner().markAsDirty(this);
        }
        if (isInitialChanges) {
            // send only required (reported) features updates
            Stream<NodeFeature> initialFeatures = Stream.concat(getFeatures().entrySet().stream().filter(entry -> isReportedFeature(entry.getKey())).map(Entry::getValue), getDisalowFeatures());
            doCollectChanges(collector, initialFeatures);
        } else {
            doCollectChanges(collector, getDisalowFeatures());
        }
    } else {
        doCollectChanges(collector, getFeatures().values().stream());
    }
}
Also used : NodeDetachChange(com.vaadin.flow.internal.change.NodeDetachChange) NodeAttachChange(com.vaadin.flow.internal.change.NodeAttachChange) NodeFeature(com.vaadin.flow.internal.nodefeature.NodeFeature)

Aggregations

NodeAttachChange (com.vaadin.flow.internal.change.NodeAttachChange)1 NodeDetachChange (com.vaadin.flow.internal.change.NodeDetachChange)1 NodeFeature (com.vaadin.flow.internal.nodefeature.NodeFeature)1