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

name option for items, so they can be accessed after copyGraph #6

Open
desandro opened this issue May 26, 2019 · 3 comments
Open

name option for items, so they can be accessed after copyGraph #6

desandro opened this issue May 26, 2019 · 3 comments
Labels
feature request New feature or request

Comments

@desandro
Copy link
Member

Add a πŸ‘ reaction to this issue if you would like to see this feature added. Do not add +1 comments β€” They will be deleted.


Right now there's no easy way to access a child of a parent copied with copyGraph.

// right arm
let upperArm = new Zdog.Shape({
  //...
});
let foreArm = new Zdog.Shape({
  addTo: upperArm,
  // ...
});
// hand
new Zdog.Shape({
  addTo: foreArm,
  color: '#C25',
  // ...
});

// left arm
upperArm.copyGraph();

// How do set the left hand to a different color?

With the name option, you could access children via an Object property.

// right arm
let upperArm = new Zdog.Shape({
  //...
});
new Zdog.Shape({
  addTo: upperArm,
  name: 'foreArm', // accessible as parent.foreArm
  // ...
});
// hand
new Zdog.Shape({
  addTo: upperArm.foreArm,
  name: 'hand', // accessible as parent.hand
  color: '#C25',
  // ...
});

// left arm
let leftArm = upperArm.copyGraph();

// set left hand to different color
leftArm.foreArm.hand.color = '#EA0';
@desandro desandro added the feature request New feature or request label May 28, 2019
@enzoferey
Copy link

enzoferey commented May 30, 2019

Hi @desandro !

I could implement this if you like.

We have two things to solve:

1. Attach the name property to the instance.

It could be done in the create function of the Anchor class, so every shape inherits it.

2. Give direct access to a child with a parent.childName syntax

You could attach a property that points to the child in the parent instance for sure, but then you have to handle name collisions (naming an item "rotate" for example). This may force to output warnings to users telling certain names are restricted when they use it (which I never really liked as a developer experience).

If we don't want to worry about name collisions, I would personally opt for a getChild("my-child-name") property that loops throughout the children property looking for an item which has the correct name.

Maybe I'm not aware of an existing way to handle dynamic properties accessors without name collisions ?

Let me know what you think about it ! πŸ˜‰

@desandro
Copy link
Member Author

@enzoferey Thanks for the the offer. I think I can handle this feature. But, I'd like to gauge outside interest before adding it in.

@gregja
Copy link

gregja commented Jun 7, 2019

Hi @desandro !
I discovered Zdog recently, and I like it a lot, it's a cool project. You made a very good job, thank's a lot.
I would appreciate to be able to set a ChildName on the graphical objects. And, if you could add a "find" function on the main object to retrieve a child by its name, it would be really great.
Thank's a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Development

No branches or pull requests

3 participants