Temporary Documents

Is there a built-in way to create temporary entities? Like entities wich are not stored in the database, but remains in memory for .update etc
8 Replies
Calego
Calego3y ago
There is! https://foundryvtt.com/api/abstract.Document.html#.create The second arg here is "context": https://foundryvtt.com/api/global.html#DocumentModificationContext So basically you can do this:
const tempItem = Item.create(data, { temporary: true });
const tempItem = Item.create(data, { temporary: true });
Magus
Magus3y ago
wow i thought it was a long shot ty! sadly... it does not work as I intended
Magus
Magus3y ago
No description
Magus
Magus3y ago
i cant use setflag nor update with a temporary journal =/
Calego
Calego3y ago
What are you attempting? If you know this information when the journal is created, you can set it then right?
Magus
Magus3y ago
Im building an application wich stores some information in journals (the easiest way I found to store things in the DB)... creating my own entities seemed to much trouble, but can also be used in a default state without any journal being selected. I thought it would be much easier to create a temporary journal in case no journal is selected instead of adding complexity to the logic behind it
Calego
Calego3y ago
Ahhh. I'm honestly not too familiar with how one manipulates temporary documents, I know it's possible and has uses but they're probably different methods than for ones that exist in the db.
Magus
Magus3y ago
I see, ty im going to make some research on this, probably there is a way, if I find out I tell you xd