We use cookies to enhance your experience on the site
CodeWorlds

Project: NOVA LAB Resource System

Time to apply all Pinia knowledge in one project! You'll build a complete NOVA LAB station resource management system that uses:

  • Store with state - storing resource data (oxygen, water, energy)
  • Getters - calculating statuses, alerts, statistics
  • Actions - CRUD operations, resource consumption, alarms
  • Store composition - resource store + alert store
  • $subscribe - monitoring changes

Project Architecture

1stores/
2β”œβ”€β”€ resources.js     # Station resources (state, getters, actions)
3└── alerts.js        # Alert system (subscribe to resources)

Data Flow

1ResourceStore (state: oxygen, water, energy)
2  β”œβ”€β”€ getters β†’ statusLevel, criticalResources, summary
3  β”œβ”€β”€ actions β†’ consume(), refill(), emergencyProtocol()
4  └── $subscribe β†’ AlertStore.checkLevels()
5
6AlertStore (state: alerts)
7  β”œβ”€β”€ getters β†’ activeAlerts, criticalCount
8  └── actions β†’ addAlert(), dismissAlert()

Task

Analyze the working system in the editor. Pay attention to:

  1. ResourceStore - how state, getters, and actions work together
  2. AlertStore - how one store reacts to changes in another
  3. App Component - how storeToRefs and actions are used in the template
  4. $subscribe - automatic alert creation when resource levels are low

Key patterns:

  • Composition API style with
    ref()
    and
    computed()
  • Asynchronous actions with try/catch/finally
  • Store composition - resource store calls alert store
  • storeToRefs
    for reactive destructuring
  • $patch
    for batch state updates
Go to CodeWorlds→