550c98f275
Reorganización física de crates/: - core/ (mezclaba 6 propósitos) se divide en protocol/, init/, runtime/, compat/ - shared/ (3 crates) se redistribuye en protocol/ e init/ - lapaloma (sub-módulo de ui_engine) se promueve a modules/pineal/ Renames de proyectos: - shipote → shuma (runtime de sandboxes) - nouser → akasha (explorador de Mónadas) - yahweh → nahual (motor GPUI, antes ui_engine/) - lapaloma → pineal (data-viz agnóstica) Fraccionamiento UI → core agnóstico: - vista-core (DeckState + snap, 175 LOC, 5 tests verdes) - barra-core (Task + render_html + sanitize, 90 LOC, 5 tests verdes) - vista-web y barra-web ahora son thin DOM bindings Documentación nueva: - 16 SDDs por subdirectorio (≤80 LOC c/u): protocol/init/runtime/compat + 10 módulos + apps/ - docs/STATUS.md con cifras reales por proyecto - docs/ROADMAP.md con plan a finalización (6 hitos, ~6-8 semanas) - CHANGELOG.md particionado en docs/changelog/<proyecto>.md (7 buckets) Automatización: - scripts/reorg.py — script idempotente que: git mv directorios, renombra package names, recomputa path = refs, reescribe imports rust, actualiza workspace Cargo.toml. Soporta --dry-run. - scripts/split-changelog.py — particiona CHANGELOG por componente. Validación: - cargo check --workspace pasa (124 crates + 2 nuevos cores). - 10 tests adicionales (5 en vista-core + 5 en barra-core) verdes. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
53 lines
1.8 KiB
Rust
53 lines
1.8 KiB
Rust
//! `Persister` — escribe el `LayoutModel` a disco en cada cambio.
|
|
//!
|
|
//! Es una entity sin estado visible (no se renderea). Solo existe para
|
|
//! mantener viva la subscripción al `LayoutModel`. Cualquier evento
|
|
//! (`StructureChanged` o `FlexChanged`) dispara una escritura sincrónica
|
|
//! al `path` configurado.
|
|
//!
|
|
//! Hoy NO hay debounce — cada drag de divisor emite UN solo `FlexChanged`
|
|
//! al final (en DragEnd, no por frame), y los swaps de kind son acción
|
|
//! manual del usuario. Si en el futuro las escrituras se vuelven
|
|
//! frecuentes, el lugar para sumar debounce es acá: spawn un task que
|
|
//! coalesce events dentro de N ms.
|
|
|
|
use std::path::PathBuf;
|
|
|
|
use gpui::{Context, Entity};
|
|
|
|
use crate::layout_model::{LayoutModel, LayoutModelEvent};
|
|
|
|
pub struct Persister {
|
|
path: PathBuf,
|
|
}
|
|
|
|
impl Persister {
|
|
pub fn new(path: PathBuf, model: Entity<LayoutModel>, cx: &mut Context<Self>) -> Self {
|
|
cx.subscribe(&model, |this: &mut Persister, model, _ev: &LayoutModelEvent, cx| {
|
|
this.write(model.read(cx).tree());
|
|
})
|
|
.detach();
|
|
Self { path }
|
|
}
|
|
|
|
fn write(&self, tree: &nahual_core::LayerConfig) {
|
|
let json = tree.serialize_json();
|
|
// Anti-loop: si el contenido en disco ya coincide, skip. Esto
|
|
// matters cuando el watcher está corriendo: persister write →
|
|
// notify modify → replace_tree → persister write → ... sin esto
|
|
// sería un loop infinito de syscalls.
|
|
if let Ok(existing) = std::fs::read_to_string(&self.path) {
|
|
if existing == json {
|
|
return;
|
|
}
|
|
}
|
|
if let Err(e) = std::fs::write(&self.path, json) {
|
|
eprintln!(
|
|
"[Persister] error escribiendo {}: {}",
|
|
self.path.display(),
|
|
e
|
|
);
|
|
}
|
|
}
|
|
}
|