fn msg(&mut self, msg: &Msg) {
        match msg {
            // Replace the current PSD with a new one
            // Happens on page load and after drag/drop
            Msg::ReplacePsd(psd) => {
                let psd = Psd::from_bytes(psd).unwrap();

                // When we upload a new PSD we set all layers to visible
                let mut layer_visibility = HashMap::new();
                for layer in psd.layers().iter() {
                    layer_visibility.insert(layer.name().to_string(), true);
                }

                self.psd = Some(psd);
                self.layer_visibility = layer_visibility;
            }
            // Set whether or not a layer is currently toggled on/off
            Msg::SetLayerVisibility(idx, visible) => {
                let visibility = self
                    .layer_visibility
                    .get_mut(
                        self.psd
                            .as_mut()
                            .unwrap()
                            .layer_by_idx(*idx)
                            .name(),
                    )
                    .unwrap();

                *visibility = *visible;
            }
            // Have we already queued up a re-render?
            Msg::SetIsRendering(is_rendering) => {
                self.is_rendering = *is_rendering;
            }
        }
    }
/// Update State given some new Msg
Update State given some new Msg
Update State given some new Msg
fn msg(&mut self, msg: &Msg) {
        match msg {
            // Replace the current PSD with a new one
            // Happens on page load and after drag/drop
            Msg::ReplacePsd(psd) => {
                let psd = Psd::from_bytes(psd).unwrap();
                // When we upload a new PSD we set all layers to visible
                let mut layer_visibility = HashMap::new();
                for layer in psd.layers().iter() {
                    layer_visibility.insert(layer.name().to_string(), true);
                }
                self.psd = Some(psd);
                self.layer_visibility = layer_visibility;
            }
            // Set whether or not a layer is currently toggled on/off
            Msg::SetLayerVisibility(idx, visible) => {
                let visibility = self
                    .layer_visibility
                    .get_mut(
                        self.psd
                            .as_mut()
                            .unwrap()
                            .layer_by_idx(*idx)
                            .name(),
                    )
                    .unwrap();
                *visibility = *visible;
            }
            // Have we already queued up a re-render?
            Msg::SetIsRendering(is_rendering) => {
                self.is_rendering = *is_rendering;
            }
        }
    }
fn msg ( & mut self , msg : & Msg ) { match msg { // Replace the current PSD with a new one // Happens on page load and after drag/drop Msg :: ReplacePsd ( psd ) => { let psd = Psd :: from_bytes ( psd ) . unwrap ( ) ; // When we upload a new PSD we set all layers to visible let mut layer_visibility = HashMap :: new ( ) ; for layer in psd . layers ( ) . iter ( ) { layer_visibility . insert ( layer . name ( ) . to_string ( ) , true ) ; } self . psd = Some ( psd ) ; self . layer_visibility = layer_visibility ; } // Set whether or not a layer is currently toggled on/off Msg :: SetLayerVisibility ( idx , visible ) => { let visibility = self . layer_visibility . get_mut ( self . psd . as_mut ( ) . unwrap ( ) . layer_by_idx ( * idx ) . name ( ) , ) . unwrap ( ) ; * visibility = * visible ; } // Have we already queued up a re-render? Msg :: SetIsRendering ( is_rendering ) => { self . is_rendering = * is_rendering ; } } }
Update State given some new Msg
Update State given some new Msg
&mut self
msg
&Msg
&mut self
msg
&Msg