Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible to get child reference from reference? #74

Closed
geirsagberg opened this issue Jun 22, 2015 · 2 comments
Closed

Possible to get child reference from reference? #74

geirsagberg opened this issue Jun 22, 2015 · 2 comments

Comments

@geirsagberg
Copy link

I want to be able to pass a reference around, and create a reference to a child cursor at a later stage, where I might not have access to the entire structure:

var userRef = structure.reference('user');
// Somewhere else
var childRef = userRef.reference('profile');

Any thoughts on how to accomplish this? Or, how to get a reference by passing a cursor to the structure, perhaps?

@mikaelbr
Copy link
Member

The new reference API actually support passing in a cursor. See https://github.com/omniscientjs/immstruct/blob/master/src/structure.js#L206. This is not documented yet, as it is unreleased. Will hopefully be released within the month. We could also extend the API allow for references to create references, something like the code below.

Structure.prototype.reference = function reference (path) { // local function name to avoid collisions

  // ...

  var self = this,
      cursor = this.cursor(path),
      unobservers = Immutable.Set();

  // ...

  return {

    reference: function (subPath) {
      return reference((cursor._keyPath || []).concat(subPath));
    },

    observe: function (eventName, newFn) {
    },

    cursor: function (subPath) {
    },
    // ... etc

Note: This is untested, but something like it should work. Pull Requests with tests and docs are very welcome! 🍰

@geirsagberg
Copy link
Author

Awesomesauce :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants