1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
use super::{super::OrdersContainer, AfterMount, IntoAfterMount, MountType, UrlHandling};
use crate::browser::Url;
use crate::virtual_dom::View;

pub struct UndefinedInitAPI;
#[allow(clippy::module_name_repetitions)]
pub struct UndefinedIntoInit;

/// Used as a flexible wrapper for the init function.
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[deprecated(
    since = "0.5.0",
    note = "Part of old Init API. Use a combination of `BeforeMount` and `AfterMount` instead."
)]
pub struct Init<Mdl> {
    /// Initial model to be used when the app begins.
    #[deprecated(
        since = "0.5.0",
        note = "Part of old Init API. Use `AfterMount` instead."
    )]
    pub model: Mdl,
    /// How to handle initial url routing. Defaults to [`UrlHandling::PassToRoutes`] in the
    /// constructors.
    #[deprecated(
        since = "0.5.0",
        note = "Part of old Init API. Use `AfterMount` instead."
    )]
    pub url_handling: UrlHandling,
    /// How to handle elements already present in the mount. Defaults to [`MountType::Append`]
    /// in the constructors.
    #[deprecated(
        since = "0.5.0",
        note = "Part of old Init API. Use `BeforeMount` instead."
    )]
    pub mount_type: MountType,
}

impl<Mdl> Init<Mdl> {
    #[deprecated(
        since = "0.5.0",
        note = "Part of old Init API. Use `AfterMount` instead."
    )]
    pub const fn new(model: Mdl) -> Self {
        Self {
            model,
            url_handling: UrlHandling::PassToRoutes,
            mount_type: MountType::Append,
        }
    }

    #[deprecated(
        since = "0.5.0",
        note = "Part of old Init API. Use `AfterMount` instead."
    )]
    pub const fn new_with_url_handling(model: Mdl, url_handling: UrlHandling) -> Self {
        Self {
            model,
            url_handling,
            mount_type: MountType::Append,
        }
    }
}

#[allow(clippy::module_name_repetitions)]
#[deprecated(
    since = "0.5.0",
    note = "Part of old Init API. Use `AfterMount` instead."
)]
pub type InitFn<Ms, Mdl, ElC, GMs> =
    Box<dyn FnOnce(Url, &mut OrdersContainer<Ms, Mdl, ElC, GMs>) -> Init<Mdl>>;

#[allow(clippy::module_name_repetitions)]
#[deprecated(
    since = "0.5.0",
    note = "Part of old Init API. Use `IntoAfterMount` and `IntoBeforeMount` instead."
)]
pub trait IntoInit<Ms: 'static, Mdl, ElC: View<Ms>, GMs> {
    fn into_init(self, init_url: Url, ord: &mut OrdersContainer<Ms, Mdl, ElC, GMs>) -> Init<Mdl>;
}

impl<Ms: 'static, Mdl, ElC: View<Ms>, GMs, F> IntoInit<Ms, Mdl, ElC, GMs> for F
where
    F: FnOnce(Url, &mut OrdersContainer<Ms, Mdl, ElC, GMs>) -> Init<Mdl>,
{
    fn into_init(self, init_url: Url, ord: &mut OrdersContainer<Ms, Mdl, ElC, GMs>) -> Init<Mdl> {
        self(init_url, ord)
    }
}

impl<Ms: 'static, Mdl, ElC: View<Ms>, GMs> IntoAfterMount<Ms, Mdl, ElC, GMs>
    for (Init<Mdl>, OrdersContainer<Ms, Mdl, ElC, GMs>)
{
    fn into_after_mount(
        self: Box<Self>,
        _: Url,
        ord: &mut OrdersContainer<Ms, Mdl, ElC, GMs>,
    ) -> AfterMount<Mdl> {
        let (init, old_ord) = *self;
        ord.merge(old_ord);
        AfterMount {
            model: init.model,
            url_handling: init.url_handling,
        }
    }
}