• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Subscription类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.reactfx.Subscription的典型用法代码示例。如果您正苦于以下问题:Java Subscription类的具体用法?Java Subscription怎么用?Java Subscription使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Subscription类属于org.reactfx包,在下文中一共展示了Subscription类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: UndoManagerImpl

import org.reactfx.Subscription; //导入依赖的package包/类
public UndoManagerImpl(
        ChangeQueue<C> queue,
        Function<? super C, ? extends C> invert,
        Consumer<C> apply,
        BiFunction<C, C, Optional<C>> merge,
        Predicate<C> isIdentity,
        EventStream<C> changeSource,
        Duration preventMergeDelay) {
    this.queue = queue;
    this.invert = invert;
    this.apply = apply;
    this.merge = merge;
    this.isIdentity = isIdentity;
    this.mark = queue.getCurrentPosition();

    Subscription mainSub = changeSource.subscribe(this::changeObserved);

    if (preventMergeDelay.isZero() || preventMergeDelay.isNegative()) {
        subscription = mainSub;
    } else {
        Subscription sub2 = changeSource.successionEnds(preventMergeDelay).subscribe(ignore -> preventMerge());
        subscription = mainSub.and(sub2);
    }
}
 
开发者ID:FXMisc,项目名称:UndoFX,代码行数:25,代码来源:UndoManagerImpl.java


示例2: create

import org.reactfx.Subscription; //导入依赖的package包/类
static <T> Val<T> create(
        Supplier<? extends T> computeValue,
        EventStream<?> invalidations) {
    return new ValBase<T>() {

        @Override
        protected Subscription connect() {
            return invalidations.subscribe(x -> invalidate());
        }

        @Override
        protected T computeValue() {
            return computeValue.get();
        }
    };
}
 
开发者ID:TomasMikula,项目名称:ReactFX,代码行数:17,代码来源:Val.java


示例3: test

import org.reactfx.Subscription; //导入依赖的package包/类
@Test
public void test() {
    Var<Integer> src = Var.newSimpleVar(1);
    Var<UnaryOperator<Integer>> fn = Var.newSimpleVar(UnaryOperator.identity());
    Val<Integer> mapped = src.mapDynamic(fn);

    assertEquals(1, mapped.getValue().intValue());

    src.setValue(2);
    assertEquals(2, mapped.getValue().intValue());

    fn.setValue(i -> i + i);
    assertEquals(4, mapped.getValue().intValue());

    Subscription sub = mapped.observeChanges((obs, oldVal, newVal) -> {
        assertEquals(4, oldVal.intValue());
        assertEquals(8, newVal.intValue());
    });
    fn.setValue(i -> i * i * i);
    sub.unsubscribe();

    fn.setValue(null);
    assertTrue(mapped.isEmpty());
}
 
开发者ID:TomasMikula,项目名称:ReactFX,代码行数:25,代码来源:MapDynamicTest.java


示例4: testLaziness

import org.reactfx.Subscription; //导入依赖的package包/类
@Test
public void testLaziness() {
    SimpleVar<String> s1 = (SimpleVar<String>) Var.newSimpleVar("a");
    SimpleVar<String> s2 = (SimpleVar<String>) Var.newSimpleVar("b");
    SimpleVar<String> s3 = (SimpleVar<String>) Var.newSimpleVar("c");

    Val<String> firstNonNull = Val.orElse(s1, s2).orElse(s3);

    assertFalse(s1.isObservingInputs());
    assertFalse(s2.isObservingInputs());
    assertFalse(s2.isObservingInputs());

    Subscription sub = firstNonNull.pin();

    assertTrue(s1.isObservingInputs());
    assertTrue(s2.isObservingInputs());
    assertTrue(s2.isObservingInputs());

    sub.unsubscribe();

    assertFalse(s1.isObservingInputs());
    assertFalse(s2.isObservingInputs());
    assertFalse(s2.isObservingInputs());
}
 
开发者ID:TomasMikula,项目名称:ReactFX,代码行数:25,代码来源:OrElseTest.java


示例5: test

import org.reactfx.Subscription; //导入依赖的package包/类
@Test
public void test() {
    ObservableList<Integer> list = FXCollections.observableArrayList();
    Val<Integer> size = LiveList.sizeOf(list);
    List<Integer> sizes = new ArrayList<>();
    Subscription sub = EventStreams.valuesOf(size).subscribe(sizes::add);
    list.add(1);
    list.addAll(2, 3, 4);
    assertEquals(Arrays.asList(0, 1, 4), sizes);

    sub.unsubscribe();
    sizes.clear();
    list.addAll(5, 6);
    assertEquals(Arrays.asList(), sizes);

    EventStreams.valuesOf(size).subscribe(sizes::add);
    list.addAll(7, 8);
    assertEquals(Arrays.asList(6, 8), sizes);
}
 
开发者ID:TomasMikula,项目名称:ReactFX,代码行数:20,代码来源:ListSizeTest.java


示例6: avoidFalseInvalidations

import org.reactfx.Subscription; //导入依赖的package包/类
private static <T> Val<T> avoidFalseInvalidations(Val<T> src) {
    return new ValBase<T>() {
        @Override
        protected T computeValue() {
            return src.getValue();
        }

        @Override
        protected Subscription connect() {
            return src.observeChanges((obs, oldVal,
                                       newVal) -> invalidate());
        }
    };
}
 
开发者ID:ChiralBehaviors,项目名称:Kramer,代码行数:15,代码来源:SizeTracker.java


示例7: assingFile

import org.reactfx.Subscription; //导入依赖的package包/类
/**
 * It allows to link the content of the file specified once called this method
 */
public void assingFile(String filePath) {

  //action when the button is pressed
  Subscription btnClicksub = EventStreams.eventsOf(this, ActionEvent.ACTION).subscribe(evt -> {
    try {
      LocalList<String> lines = new LocalList<String>();
      lines.addAll(Files.readAllLines(FileSystems.getDefault().getPath(filePath)));
      Utils.clipBoardListener.setContentCB(lines.toString());
    } catch (IOException e) {
      Logger.getGlobal().log(Level.WARNING, e.getMessage());
    }
  });
}
 
开发者ID:ames89,项目名称:clippyboard,代码行数:17,代码来源:ButtonJs.java


示例8: avoidFalseInvalidations

import org.reactfx.Subscription; //导入依赖的package包/类
private static <T> Val<T> avoidFalseInvalidations(Val<T> src) {
    return new ValBase<T>() {
        @Override
        protected Subscription connect() {
            return src.observeChanges((obs, oldVal, newVal) -> invalidate());
        }

        @Override
        protected T computeValue() {
            return src.getValue();
        }
    };
}
 
开发者ID:FXMisc,项目名称:Flowless,代码行数:14,代码来源:SizeTracker.java


示例9: observeInputs

import org.reactfx.Subscription; //导入依赖的package包/类
@Override
protected Subscription observeInputs() {
    return parChanges.subscribe(mod -> {
        mod = mod.trim();
        QuasiListModification<Paragraph<PS, SEG, S>> qmod =
                QuasiListModification.create(mod.getFrom(), mod.getRemoved(), mod.getAddedSize());
        notifyObservers(qmod.asListChange());
    });
}
 
开发者ID:FXMisc,项目名称:RichTextFX,代码行数:10,代码来源:GenericEditableStyledDocumentBase.java


示例10: connect

import org.reactfx.Subscription; //导入依赖的package包/类
@Override
protected Subscription connect() {
    oldValue = src.getValue();
    return Val.observeChanges(src, (obs, oldVal, newVal) -> {
        oldValue = getValue();
        Duration d = duration.apply(oldValue, newVal);
        transition.setDuration(d);
        transition.playFromStart();
    });
}
 
开发者ID:TomasMikula,项目名称:ReactFX,代码行数:11,代码来源:AnimatedVal.java


示例11: invalidations

import org.reactfx.Subscription; //导入依赖的package包/类
/**
 * Returns a stream of invalidated values, which emits the invalidated value
 * (i.e. the old value) on each invalidation of this observable value.
 */
default EventStream<T> invalidations() {
    return new EventStreamBase<T>() {
        @Override
        protected Subscription observeInputs() {
            return observeInvalidations(this::emit);
        }
    };
}
 
开发者ID:TomasMikula,项目名称:ReactFX,代码行数:13,代码来源:Val.java


示例12: observeChanges

import org.reactfx.Subscription; //导入依赖的package包/类
static <T> Subscription observeChanges(
        ObservableValue<? extends T> obs,
        ChangeListener<? super T> listener) {
    if(obs instanceof Val) {
        return ((Val<? extends T>) obs).observeChanges(listener);
    } else {
        obs.addListener(listener);
        return () -> obs.removeListener(listener);
    }
}
 
开发者ID:TomasMikula,项目名称:ReactFX,代码行数:11,代码来源:Val.java


示例13: connect

import org.reactfx.Subscription; //导入依赖的package包/类
@Override
protected Subscription connect() {
    trySrc = true;
    Subscription sub1 = Val.observeInvalidations(src, obs -> {
        trySrc = true;
        invalidate();
    });
    Subscription sub2 = Val.observeInvalidations(other, obs -> {
        if(!trySrc) {
            invalidate();
        }
    });
    return sub1.and(sub2);
}
 
开发者ID:TomasMikula,项目名称:ReactFX,代码行数:15,代码来源:OrElse.java


示例14: connect

import org.reactfx.Subscription; //导入依赖的package包/类
@Override
protected Subscription connect() {
    if(boundTo != null) {
        boundTo.addListener(boundToListener);
    }

    return () -> {
        if(boundTo != null) {
            boundTo.removeListener(boundToListener);
        }
    };
}
 
开发者ID:TomasMikula,项目名称:ReactFX,代码行数:13,代码来源:SimpleVar.java


示例15: connect

import org.reactfx.Subscription; //导入依赖的package包/类
@Override
protected Subscription connect() {
    assert tree == null;
    tree = FingerTree.mkTree(input, monoid);
    return LiveList.observeChanges(input, ch -> {
        for(ListModification<? extends T> mod: ch) {
            FingerTree<T, T> left = tree.split(mod.getFrom())._1;
            FingerTree<T, T> right = tree.split(mod.getFrom() + mod.getRemovedSize())._2;
            FingerTree<T, T> middle = FingerTree.mkTree(mod.getAddedSubList(), monoid);
            tree = left.join(middle).join(right);
        }
        invalidate();
    })
    .and(() -> tree = null);
}
 
开发者ID:TomasMikula,项目名称:ReactFX,代码行数:16,代码来源:ListReduction.java


示例16: quasiChanges

import org.reactfx.Subscription; //导入依赖的package包/类
default EventStream<QuasiListChange<? extends E>> quasiChanges() {
    return new EventStreamBase<QuasiListChange<? extends E>>() {
        @Override
        protected Subscription observeInputs() {
            return observeQuasiChanges(this::emit);
        }
    };
}
 
开发者ID:TomasMikula,项目名称:ReactFX,代码行数:9,代码来源:LiveList.java


示例17: quasiModifications

import org.reactfx.Subscription; //导入依赖的package包/类
default EventStream<QuasiListModification<? extends E>> quasiModifications() {
    return new EventStreamBase<QuasiListModification<? extends E>>() {
        @Override
        protected Subscription observeInputs() {
            return observeQuasiModifications(this::emit);
        }
    };
}
 
开发者ID:TomasMikula,项目名称:ReactFX,代码行数:9,代码来源:LiveList.java


示例18: observeQuasiChanges

import org.reactfx.Subscription; //导入依赖的package包/类
static <E> Subscription observeQuasiChanges(
        ObservableList<? extends E> list,
        QuasiChangeObserver<? super E> observer) {
    if(list instanceof LiveList) {
        LiveList<? extends E> lst = (LiveList<? extends E>) list;
        return lst.observeQuasiChanges(observer);
    } else {
        ListChangeListener<E> listener = ch -> {
            QuasiListChange<? extends E> change = QuasiListChange.from(ch);
            observer.onChange(change);
        };
        list.addListener(listener);
        return () -> list.removeListener(listener);
    }
}
 
开发者ID:TomasMikula,项目名称:ReactFX,代码行数:16,代码来源:LiveList.java


示例19: observeChanges

import org.reactfx.Subscription; //导入依赖的package包/类
static <E> Subscription observeChanges(
        ObservableList<E> list,
        Consumer<? super ListChange<? extends E>> observer) {

    return observeQuasiChanges(
            list, qc -> observer.accept(QuasiListChange.instantiate(qc, list)));
}
 
开发者ID:TomasMikula,项目名称:ReactFX,代码行数:8,代码来源:LiveList.java


示例20: quasiChangesOf

import org.reactfx.Subscription; //导入依赖的package包/类
static <E> EventStream<QuasiListChange<? extends E>> quasiChangesOf(
        ObservableList<E> list) {
    if(list instanceof LiveList) {
        LiveList<E> lst = (LiveList<E>) list;
        return lst.quasiChanges();
    } else {
        return new EventStreamBase<QuasiListChange<? extends E>>() {
            @Override
            protected Subscription observeInputs() {
                return LiveList.<E>observeQuasiChanges(list, this::emit);
            }
        };
    }
}
 
开发者ID:TomasMikula,项目名称:ReactFX,代码行数:15,代码来源:LiveList.java



注:本文中的org.reactfx.Subscription类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java DeleteMessageBatchResult类代码示例发布时间:2022-05-22
下一篇:
Java ASN1Null类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap