@moondaisy wrote:
Hello, I’m new to Ember and I’m trying to store a simple model locally using
ember-local-storage
(setted up following this).This is my model:
import { Model, attr } from '@ember-data/model'; export default class ScoresModel extends Model { @attr('number') scoreX; @attr('number') scoreO; }
The idea behind it is being able to store the scores of a simple game while the user doesn’t close the browser. I would like to create a singleton object of this type when the app initializes (or load the existing one) so then I can show the scores in a specific route of my app.
From what I understood on the doc I can use
this.store
on route or controllers files. But I don’t know where would be the right place to create or find this Scores record so that it is available everywhere. The main part of the game is a component, I was hoping to be able to update the stored values there but I guess that won’t work, and then I should be able to access the object and show it from at the /scores route.Any pointers in the right direction or links to tutorials/code that does something like this would be great. Thanks!
Posts: 4
Participants: 3