Adding in apply and apply_if methods

This commit is contained in:
Pauan 2018-10-29 23:06:22 -10:00
parent 09a788e66f
commit b0a638eeb8
3 changed files with 31 additions and 1 deletions

View File

@ -1,3 +1,10 @@
Zero-cost virtual DOM for Rust!
This crate is super unstable! Don't use it to build anything serious, there ***will*** be breaking changes!
Status
======
It is generally feature complete, though more convenience methods might be added over time.
It is relatively stable: breaking changes are rare, and are handled with the normal semver system.
You must use the Nightly Rust compiler (because it is needed for futures 0.3)

View File

@ -447,11 +447,32 @@ impl<A> DomBuilder<A> {
self
}
#[inline]
pub fn apply<F>(self, f: F) -> Self where F: FnOnce(Self) -> Self {
self.apply_if(true, f)
}
#[inline]
pub fn apply_if<F>(self, test: bool, f: F) -> Self where F: FnOnce(Self) -> Self {
if test {
f(self)
} else {
self
}
}
#[deprecated(since = "0.3.2", note = "Use apply instead")]
#[allow(deprecated)]
#[inline]
pub fn mixin<B: Mixin<Self>>(self, mixin: B) -> Self {
self.mixin_if(true, mixin)
}
#[deprecated(since = "0.3.2", note = "Use apply_if instead")]
#[allow(deprecated)]
#[inline]
pub fn mixin_if<B: Mixin<Self>>(self, test: bool, mixin: B) -> Self {
if test {

View File

@ -3,10 +3,12 @@ use dom::RefFn;
pub use animation::AnimatedSignalVec;
#[deprecated(since = "0.3.2", note = "Use the apply or apply_if methods instead")]
pub trait Mixin<A> {
fn apply(self, builder: A) -> A;
}
#[allow(deprecated)]
impl<A, F> Mixin<A> for F where F: FnOnce(A) -> A {
#[inline]
fn apply(self, builder: A) -> A {