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

SetTracking Graph Traversal #6

Open
tonysneed opened this issue Sep 14, 2017 · 3 comments
Open

SetTracking Graph Traversal #6

tonysneed opened this issue Sep 14, 2017 · 3 comments
Assignees
Labels
Milestone

Comments

@tonysneed
Copy link

tonysneed commented Sep 14, 2017

  • setTracking method will need to traverse graph to recursively set tracking.
    • Use traverse package to detect cycles.
@omatrot
Copy link

omatrot commented Sep 6, 2019

Hi @tonysneed.
Is there a particular reason this is not available yet?
I would need that kind of method but it seems not so easy to implement even with a recursive graph iterator. Did you give it a try and posponed it because of your early findings?

@tonysneed
Copy link
Author

I haven’t had time to get this package to where I’d like it. Happy to accept PR’s though! :)

@omatrot
Copy link

omatrot commented Sep 11, 2019

Right now I wrote a utility static class of my own, using the recursive-iterator package:

import { TrackableEntity } from "trackable-entities";
import RecursiveIterator from "recursive-iterator";

export class MySetTrackingHelper {
  public static setTrackingOnObjectGraph(
    e: TrackableEntity,
    on: boolean = true
  ) {
    var iterator = new RecursiveIterator(e, undefined, true);
    for (let { parent } of iterator) {
      if (
        this.getPropertyDescriptor(parent, "tracking") &&
        this.getPropertyDescriptor(parent, "tracking").get != undefined
      ) {
        parent.tracking = on;
      } else {
        continue;
      }
    }
  }
  private static getPropertyDescriptor(
    obj: any,
    prop: string
  ): PropertyDescriptor {
    let desc;
    do {
      desc = Object.getOwnPropertyDescriptor(obj, prop);
    } while (!desc && (obj = Object.getPrototypeOf(obj)));
    return desc;
  }
}

I'd be happy to make a pull request as long as your give me directions on how to restructure this for it to fit in your setTracking implementation.

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

No branches or pull requests

2 participants