com.spotify.mobius.Next.noChange()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(4.2k)|赞(0)|评价(0)|浏览(88)

本文整理了Java中com.spotify.mobius.Next.noChange()方法的一些代码示例,展示了Next.noChange()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Next.noChange()方法的具体详情如下:
包路径:com.spotify.mobius.Next
类名称:Next
方法名:noChange

Next.noChange介绍

[英]Create an empty Next that doesn't update the model or dispatch effects.
[中]创建一个不更新模型或分派效果的空下一个。

代码示例

代码示例来源:origin: spotify/mobius

@Nonnull
 @Override
 public Next<M, F> handleInnerEffects(M model, boolean modelUpdated, Set<FI> innerEffects) {
  return modelUpdated ? Next.<M, F>next(model) : Next.<M, F>noChange();
 }
};

代码示例来源:origin: spotify/mobius

@Nonnull
 @Override
 public Next<String, Long> update(String model, Integer event) {
  if (event == 0) {
   return Next.noChange();
  }
  Set<Long> effects = Sets.newHashSet();
  for (int i = 0; i < event; i++) {
   effects.add(10L * (i + 1));
  }
  return Next.next(model + "->" + event, effects);
 }
},

代码示例来源:origin: spotify/mobius

@Nonnull
 @Override
 public Next<M, F> handleInnerEffects(M model, boolean modelUpdated, Set<FI> innerEffects) {
  if (innerEffects.isEmpty()) {
   return modelUpdated ? Next.<M, F>next(model) : Next.<M, F>noChange();
  }
  Set<F> effects = new HashSet<>();
  for (FI innerEffect : innerEffects) {
   F outerEffect = checkNotNull(f).apply(innerEffect);
   effects.add(checkNotNull(outerEffect));
  }
  if (modelUpdated) {
   return Next.next(model, effects);
  } else {
   return Next.dispatch(effects);
  }
 }
};

代码示例来源:origin: spotify/mobius

@Test
public void testHasModelFail() throws Exception {
 next = noChange();
 matcher = hasModel();
 assertFalse(matcher.matches(next));
 matcher.describeMismatch(next, desc);
 assertEquals("no model", desc.toString());
}

代码示例来源:origin: spotify/mobius

@Test
public void testHasModelSpecificButMissing() throws Exception {
 next = noChange();
 matcher = hasModel(equalTo("a"));
 assertFalse(matcher.matches(next));
 matcher.describeMismatch(next, desc);
 assertEquals("no model", desc.toString());
}

代码示例来源:origin: spotify/mobius

@Test
public void testHasNoEffectsMatch() throws Exception {
 next = noChange();
 matcher = hasNoEffects();
 assertTrue(matcher.matches(next));
 matcher.describeMismatch(next, desc);
 assertEquals("no effects", desc.toString());
}

代码示例来源:origin: spotify/mobius

@Test
public void testHasEffectsSpecificButMissing() throws Exception {
 next = noChange();
 matcher = hasEffects(hasItems(1, 2, 3));
 assertFalse(matcher.matches(next));
 matcher.describeMismatch(next, desc);
 assertEquals("no effects", desc.toString());
}

代码示例来源:origin: spotify/mobius

@Test
public void testHasNothing() throws Exception {
 matcher = hasNothing();
 assertFalse(matcher.matches(null));
 assertFalse(matcher.matches(next("1234")));
 assertFalse(matcher.matches(dispatch(effects("f1"))));
 assertFalse(matcher.matches(next("123", effects("f1"))));
 assertTrue(matcher.matches(noChange()));
}

代码示例来源:origin: spotify/mobius

@Test
public void nextNoopHasNoModelAndNoEffects() throws Exception {
 Next<String, String> next = noChange();
 assertFalse(next.hasModel());
 assertFalse(next.hasEffects());
}

代码示例来源:origin: spotify/mobius

@Test
public void noChangeDoesNotCallModelUpdater() throws Exception {
 InnerUpdate<String, String, String, String, String, String> innerUpdate =
   InnerUpdate.<String, String, String, String, String, String>builder()
     .modelExtractor(m -> m)
     .eventExtractor(e -> e)
     .innerUpdate((model, event) -> noChange())
     .modelUpdater((m, mi) -> "model_updater")
     .innerEffectHandler(ignoreEffects())
     .build();
 Next<String, String> next = innerUpdate.update("model", "event");
 assertThat(next, NextMatchers.<String, String>hasNothing());
}

代码示例来源:origin: spotify/mobius

@Test
public void noChangeNoEffectsStillCallsInnerEffectHandler() throws Exception {
 InnerUpdate<String, String, String, String, String, String> innerUpdate =
   InnerUpdate.<String, String, String, String, String, String>builder()
     .modelExtractor(m -> m)
     .eventExtractor(e -> e)
     .innerUpdate((model, event) -> noChange())
     .modelUpdater((m, mi) -> mi)
     .innerEffectHandler((model, updated, effects) -> Next.next("effect_handler"))
     .build();
 Next<String, String> next = innerUpdate.update("model", "event");
 assertThat(next, NextMatchers.<String, String>hasModel("effect_handler"));
 assertThat(next, NextMatchers.<String, String>hasNoEffects());
}

相关文章