Ticket #953 (closed enhancement: wontfix)

Opened 4 years ago

Last modified 4 years ago

getValue should support fallback value

Reported by: FND Owned by: FND
Priority: major Milestone: 2.6
Component: core Version:
Severity: low Keywords:
Cc:

Description

The TiddlyWiki.prototype.getValue accessor should take an optional argument specifying a default value.

Ideally, this would default to using defaultCustomFields as fallback.

Change History

follow-up: ↓ 2   Changed 4 years ago by FND

  • status changed from new to closed
  • resolution set to wontfix

Fallback idiom can be used instead:

store.getValue(tiddler, field) || fallback;

in reply to: ↑ 1   Changed 4 years ago by EricShulman

Replying to FND:

Fallback idiom can be used instead: {{{

store.getValue(tiddler, field) fallback; }}}

When used within a larger expression, you may need additional parentheses to ensure the correct order of operators within the expression, like this:

var foo=....(store.getValue(tiddler, field)||fallback)....;

Although I concur that it is not necessary to add the fallback as a argument passed to getValue, it would reduce the amount of puncuation needed and makes the syntax a little bit cleaner, and thus less prone to programming errors.

var foo=....store.getValue(tiddler, field, fallback)....;

  Changed 4 years ago by FND

  • status changed from closed to reopened
  • resolution wontfix deleted
  • milestone changed from 2.5.1 to 2.5.2

Having thought about this a little more myself, there's another drawback to using this idiom: If a value is returned which evaluates to false, the fallback is used erroneously.

While this is currently unlikely to happen (tiddler fields are strings), it should nevertheless be considered.

  Changed 4 years ago by FND

  • milestone changed from 2.5.3 to 2.5.4

  Changed 4 years ago by FND

  • status changed from reopened to closed
  • resolution set to wontfix

fallback idiom is more explicit

Note: See TracTickets for help on using tickets.