From 68c3a2d138be27f2dfc6d5554f20ca1c7ff7c4c3 Mon Sep 17 00:00:00 2001 From: tamohannes Date: Mon, 17 Aug 2026 16:01:14 -0700 Subject: [PATCH] Seed the movies demo once instead of on every boot `init` set the whole shelf unconditionally, so starting the demo a second time replaced everything the user had logged with the four sample rows. The About page in that same demo says "Every row lives in rocksdb. Restart, everything is still there." Guard the seed on `State.total.missing()` so it fires only against a store that has never been written. `selected` stays unconditional: it is a cursor into the detail page, not user data. Same change in both copies, `examples/movies.py` and the bundled `nu demo movies`. Co-Authored-By: Claude Opus 5 (1M context) --- examples/movies.py | 14 ++++++++++---- src/nu/_cli/demos/movies.py | 14 ++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/examples/movies.py b/examples/movies.py index 0a776c68..9e0bd00b 100644 --- a/examples/movies.py +++ b/examples/movies.py @@ -279,11 +279,17 @@ def _rows_filtered() -> nu.Nu: ) +# Seed once, on a store that has never been written. A restart then keeps what +# the user logged instead of replacing the shelf with the samples again. +# `selected` stays unconditional: it is a cursor into the detail page, not data. init = nu.kv.Transaction( - State.total.set(len(_SEED_MOVIES)) - | State.watched.set(sum(1 for m in _SEED_MOVIES if m["watched"])) - | State.latest_title.set(_SEED_MOVIES[-1]["title"]) - | State.movies.set(_SEED_MOVIES) + nu.IfDo( + State.total.missing(), + State.total.set(len(_SEED_MOVIES)) + | State.watched.set(sum(1 for m in _SEED_MOVIES if m["watched"])) + | State.latest_title.set(_SEED_MOVIES[-1]["title"]) + | State.movies.set(_SEED_MOVIES), + ) | State.selected.set(0), ) diff --git a/src/nu/_cli/demos/movies.py b/src/nu/_cli/demos/movies.py index ba57ce2b..6c8575d5 100644 --- a/src/nu/_cli/demos/movies.py +++ b/src/nu/_cli/demos/movies.py @@ -329,11 +329,17 @@ def _rows_filtered() -> nu.Nu: ) +# Seed once, on a store that has never been written. A restart then keeps what +# the user logged instead of replacing the shelf with the samples again. +# `selected` stays unconditional: it is a cursor into the detail page, not data. init = nu.kv.Transaction( - State.total.set(len(_SEED_MOVIES)) - | State.watched.set(sum(1 for m in _SEED_MOVIES if m["watched"])) - | State.latest_title.set(_SEED_MOVIES[-1]["title"]) - | State.movies.set(_SEED_MOVIES) + nu.IfDo( + State.total.missing(), + State.total.set(len(_SEED_MOVIES)) + | State.watched.set(sum(1 for m in _SEED_MOVIES if m["watched"])) + | State.latest_title.set(_SEED_MOVIES[-1]["title"]) + | State.movies.set(_SEED_MOVIES), + ) | State.selected.set(0), )