Skip to content
This repository was archived by the owner on Oct 14, 2018. It is now read-only.
This repository was archived by the owner on Oct 14, 2018. It is now read-only.

Implement default values at a subtree #38

Open

Description

@dustingetz

The problem is that, React state has getInitialState, so the default state can be defined inside the component. With cursors, the default state has to be declared somewhere else, at the top.

So suppose refine could take an optional extra argument, a fallback value

state = {a: {b: null }}

cursor.refine(['a', 'b']).value //=> null
var not_found = {c: {d: 42}}
c2 = cursor.refine(['a', 'b'], not_found);
c3 = c2.refine(['c', 'd']);
c3.value //> 42
c3.set(c3.value + 1); //> {a: {b: {c: {d: 43}}}}

I did implemented this in clojurescript and I found this helped clean up my components quite a bit.

Activity

  1. dustingetz commented on Dec 9, 2015

    @dustingetz
    OwnerAuthor

    The thoughtwork for this is done, we have a working clojure implementation. However, we will need to remove the varargs from refine - so the first argument needs to be a list. So this will break api compat and add some verbosity.

  2. added this to the 2.0 milestone on Jan 16, 2016
  3. dustingetz commented on Jan 16, 2016

    @dustingetz
    OwnerAuthor

    I want this for 2.0 but i don't want to break API compat, i may introduce a new API for this e.g. refineWithDefault or refineWith i have to think about the naming

  4. danielmiladinov commented on Feb 14, 2016

    @danielmiladinov
    Collaborator

    Here's a compromise: we could do type-checking on the varargs - Unless the last arg to refine is a string, consider it a default value for the path given so far?

    Of course, this would preclude strings from being default values, but it would preserve API compat.
    What other edge cases does this run into?
    I'm not super thrilled by the idea, but I'm just throwing it out there for your thoughts.

  5. dustingetz commented on Feb 14, 2016

    @dustingetz
    OwnerAuthor

    String default values are a very common case i think

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions