@@ -56,6 +56,9 @@ pub struct Data {
5656
5757 // ── Widgets ─────────────────────────────────────────────────────────────────────────────────
5858
59+/// Every widget kind in the library, as (file name, widget): what a host loads.
60+pub type Kinds = &'static [(&'static str, &'static Widget)];
61+
5962 /// Each widget file declares `pub const WIDGET: Widget`.
6063 pub struct Widget {
6164 pub title: &'static str,
@@ -101,8 +104,8 @@ pub struct Cx<'a> {
101104 /// Unix seconds. The app renders at least once a second; `animate` asks for more.
102105 pub now: f64,
103106 pub data: &'a Data,
104- /// This instance's own folder. What it keeps there survives restarts, and the app
105- /// restarts every time the library changes.
107+ /// This instance's own folder. What it keeps there survives restarts, and every library
108+ /// change, which drops the instance and makes it again from the new code.
106109 pub dir: PathBuf,
107110 live: &'a Live,
108111 }
@@ -125,8 +128,8 @@ impl Cx<'_> {
125128 }
126129
127130 /// Every widget kind in the library, as (name, widget).
128- pub fn kinds(&self) -> &'static [(&'static str, &'static Widget)] {
129- super::ALL
131+ pub fn kinds(&self) -> Kinds {
132+ self.live.kinds
130133 }
131134
132135 /// Acts on the app from anywhere a widget runs (view, update, event), not only handlers:
@@ -137,8 +140,8 @@ impl Cx<'_> {
137140 }
138141
139142 /// Call it from `update` while this instance has work that must go on when nothing shows
140- /// it, such as music playing: the app brings it back after a restart (every library change
141- /// restarts the app), even when no parent renders it. Stop calling it when the work stops.
143+ /// it, such as music playing: the app brings it back after a library change or a restart,
144+ /// even when no parent renders it. Stop calling it when the work stops.
142145 pub fn keep_running(&self) {
143146 self.live.running.borrow_mut().insert(self.id.to_owned());
144147 }
@@ -232,6 +235,7 @@ pub fn quote(s: &str) -> String {
232235 /// Every widget instance, what they share, and what they asked of the host.
233236 pub struct Live {
234237 pub data: Data,
238+ kinds: Kinds,
235239 base: PathBuf,
236240 instances: HashMap<String, (String, Box<dyn View>)>,
237241 shared: BTreeMap<String, String>,
@@ -302,15 +306,15 @@ impl Live {
302306 }
303307
304308 impl Live {
305- /// Instances keep their folders under `base`, and shared values in `base/shared.tsv`.
306- pub fn new(base: PathBuf) -> Self {
309+ /// Instances of `kinds` keep their folders under `base`, and shared values in `base/shared.tsv`.
310+ pub fn new(base: PathBuf, kinds: Kinds) -> Self {
307311 let shared = std::fs::read_to_string(base.join("shared.tsv")).unwrap_or_default().lines()
308312 .filter_map(|l| l.split_once('\t').map(|(k, v)| (k.to_owned(), v.replace("\\n", "\n"))))
309313 .collect();
310314 // Instances that were keeping work going come back now, shown or not.
311315 let wanted: Vec<(String, String)> = std::fs::read_to_string(base.join("running.tsv")).unwrap_or_default().lines()
312316 .filter_map(|l| l.split_once('\t').map(|(id, kind)| (id.to_owned(), kind.to_owned()))).collect();
313- Live { data: Data::default(), base, instances: HashMap::new(), shared, wanted: RefCell::new(wanted),
317+ Live { data: Data::default(), kinds, base, instances: HashMap::new(), shared, wanted: RefCell::new(wanted),
314318 animate: Cell::new(false), outbox: vec![], spare: TextEdit::new(""), dirty: false,
315319 later: RefCell::new(vec![]), running: RefCell::new(BTreeSet::new()), kept: BTreeSet::new() }
316320 }
@@ -337,7 +341,7 @@ impl Live {
337341 let wanted = std::mem::take(self.wanted.get_mut());
338342 let mut made = false;
339343 for (id, kind) in wanted {
340- let Some((_, w)) = super::ALL.iter().find(|(n, _)| *n == kind) else { continue };
344+ let Some((_, w)) = self.kinds.iter().find(|(n, _)| *n == kind) else { continue };
341345 if self.instances.get(&id).is_some_and(|(k, _)| *k == kind) { continue; }
342346 let cx = self.cx(&id, now());
343347 let _ = std::fs::create_dir_all(&cx.dir);
@@ -350,7 +354,18 @@ impl Live {
350354
351355 /// Offers new widget `kind` to instance `id`, at `at` in its points. Whether it kept it.
352356 pub fn mount(&mut self, id: &str, at: (f32, f32), kind: &str) -> bool {
353- super::ALL.iter().any(|(n, _)| *n == kind) && self.with(id, |w, cx| w.mount(kind, at, cx)) == Some(true)
357+ self.kinds.iter().any(|(n, _)| *n == kind) && self.with(id, |w, cx| w.mount(kind, at, cx)) == Some(true)
358+ }
359+
360+ /// A new build of the library: every instance is dropped, then made again from its kind's
361+ /// new code, before the next render. What they asked with `cx.act` runs first, against
362+ /// the old instances. Kinds the new build doesn't have are gone.
363+ pub fn reload(&mut self, kinds: Kinds) {
364+ self.apply();
365+ let all: Vec<(String, String)> = self.instances.drain().map(|(id, (kind, _))| (id, kind)).collect();
366+ self.kinds = kinds;
367+ self.wanted.get_mut().extend(all);
368+ self.make_wanted();
354369 }
355370
356371 /// Instances of `kind`, or any instance if `kind` is empty.