Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
    • Switch to GitLab Next
  • Sign in / Register
Foundry Virtual Tabletop
Foundry Virtual Tabletop
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 587
    • Issues 587
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 0
    • Merge Requests 0
  • Requirements
    • Requirements
    • List
  • Operations
    • Operations
    • Incidents
  • Analytics
    • Analytics
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • Foundry Network
  • Foundry Virtual TabletopFoundry Virtual Tabletop
  • Issues
  • #1625

Closed
Open
Opened Nov 01, 2019 by Andrew@aaclaytonOwner

Propose special syntax for mergeObject to delete keys from an existing object during the merge

API Proposal As you likely can tell by now, I love my mergeObject helper and I use it a lot to simplify code in many places. Despite it's advantages one key limitation of this approach has been the resulting inability to remove existing keys from an object by way of a merge operation.

Example Problem

const obj = {foo: "bar", delete: "me"};
mergeObject(obj, {delete: null});    // No matter what you do
mergeObject(obj, {foo: "baz"});     // obj.delete still exists

Proposed Solution In order to get around this and allow the possibility to remove expired or deprecated data from an existing object in the data model, we can add a special syntax to designate a key to be deleted instead of merged. We can choose some syntax that is very unlikely (but not impossible) to collide with normal usage.

Example Solution Prefix a key with -= AND set it's value to null to remove it from the object.

const obj = {foo: "bar", delete: "me"};
mergeObject(obj, {"-=delete": null});    // Returns {foo: "bar"}

Thoughts? Concerns? Comments? Alternative syntax you think would be better?

Practical Example An example of how you might use this in practice -- currently if you set a flag on an entity, there is never any way to remove that flag key - you can only null it out. So for example

actor.setFlag("module", "bogus", "oops");  // now you have actor.data.flags.module = {bogus: "oops"}

Before this change the best you could do was set it to null or false

actor.setFlag("module", "bogus", null);  // now you have actor.data.flags.module = {bogus: null}

Now you can actually remove the "bogus" flag with

actor.setFlag("module", "-=bogus", null); // now you have actor.data.flags.module = {}
Edited Nov 01, 2019 by Andrew
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Beta 0.4.0
Milestone
Beta 0.4.0 (Past due)
Assign milestone
Time tracking
None
Due date
None
Reference: foundrynet/foundryvtt#1625