DrSensor / nusa

(status: REWRITING it into different project) incremental runtime that bring both simplicity and power into webdev (buildless, cross-language, data-driven)
MIT License
4 stars 0 forks source link

Data lifetime across pages #14

Open DrSensor opened 2 years ago

DrSensor commented 2 years ago

Control the lifetime of the class. Whatever it should persist across page or reset on every page navigation.

mass control

<render-scope data-persist>
  <!-- all scripts class in here will be persisted when navigating to other page -->
</render-scope<

or make it default

<script data-persist src="https://esm.run/wiles/render-scope.js"></script>

granular control

import { vary, keep, persist } from "https://esm.run/wiles/decorator" // ignore data-persist attribute
export default class {
  @vary accessor start = 0 // swap databank with new array
  @keep accessor end = 10 // keep databank on every navigation or append if page/component/scope not yet cached
  @persist accessor total: number // stored in IndexDB on each eventful write
  accessor count = 1 // behavior depend on data-persist attribute
}

or without decorator (not sure if I gonna support this 🤔)

<link as="script" data-persist="total count" href="script.js">

Requirement:

DrSensor commented 1 year ago

https://github.com/DrSensor/nusa/commit/1a9b553c2364dea7f7cf517b4e7c6ba436a9ca93