question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Autovivification documentation is misleading

See original GitHub issue

Thanks for documenting autovivification in your README. This will provide a response to the many people who run into this, as you’ve no doubt noticed by the number of github tickets related to this (on the react as well as your bugtracker). A few points though:

  1. The fundamental reason why autovivifying arrays in JS is difficult is that the same [] operator is used for both array and object access so there is no way to disambiguate which one an autovivification is intended to create. However, update is not implementing JS, but instead its own mini-language. There’s no reason that we can’t decide “path” autovivification is only supported for objects, which in my experience is what is needed in the vast majority of instances (note that all tickets on the react and your bugtrackers are suggesting object autovivification only).

  2. Even in the cases where you wish to autovivify an array, $push, $splice, and $unshift can be used to create arrays with no ambiguity (at the leaf level only). Again, anecdotally, $push seems to be a much more common way of adding to an existing array than $set. Since it’s obvious $push and company intend to operate on arrays, there is no problem autovivifying in these cases.

  3. Your suggested example using $apply has three issues from my perspective:

    • $apply updates cannot be transferred between client and server since functions cannot be serialised
    • Each $apply has two code paths (the default []/{} path and the path for when the target already exists) and therefore ought to be tested in both scenarios
    • Although subjective, to me this method seems more complicated and difficult to maintain
  4. Adding autovification to update is not “practically impossible”. In fact, I have implemented it in my version: update-immutable. If you choose to not implement autovivification in your module (a decision I sympathise but do not agree with) then can you at least please link to a “dissenting opinion” on this topic?

Regards,

Doug

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
xavibonellcommented, Oct 17, 2017

I just run into this issue, at first I couldn’t believe autovivification was not implemented by default. I switched to @hoytech solution, works out of the box. You should really consider implement that solution on your repo, not just in your README, is a must have. Thanks both anyway for making everyone else’s life easier!

0reactions
kolodnycommented, Jul 11, 2017

Updated docs in 2.3.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

Developers - Autovivification documentation is misleading -
4) Adding autovification to update is not "practically impossible". In fact, I have implemented it in my version: update-immutable. If you choose to...
Read more >
What is autovivification? - Perl Maven
The simple cases for hashes. The simplest form of autovivification is when you have a hash and you set a value of a...
Read more >
Fix disable autovivification on false · Issue #34589 - GitHub
Auto-creation of arrays from false value is not allowed since PHP 8.1 - PHP RFC: Deprecate autovivification on false. ToDo: Fix all detected ......
Read more >
Turn off autovivification when you don't want it
The autovivification pragma, which you can get from CPAN, ... It stills returns false when you try exists and the element isn't there...
Read more >
Auto Vivification - Wiki
So-called AutoVivification is a PerlLanguage feature allowing complex nested data structures to spring into existence based on the types implied in the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found