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

TypeError: e.slice is not a function when calling removeNodeId #899

Open
ManiaMelon opened this issue Sep 15, 2024 · 2 comments
Open

TypeError: e.slice is not a function when calling removeNodeId #899

ManiaMelon opened this issue Sep 15, 2024 · 2 comments

Comments

@ManiaMelon
Copy link

ManiaMelon commented Sep 15, 2024

I'm encountering an error when trying to remove a node using editor.removeNodeId(nodeId) in the Drawflow library. The error message is:

TypeError: e.slice is not a function

It seems that removeNodeId expects the node ID to be a string to always start with 'node-'

Steps to Reproduce

  1. Add a Node:

    const nodeId = editor.addNode('example', 1, 1, 100, 100, 'example-node', {}, '<div>Example Node</div>');

    addNode returns a numeric nodeId.

  2. Attempt to Remove the Node:

    editor.removeNodeId(nodeId); // nodeId is a number
  3. Error Occurs:

    TypeError: e.slice is not a function
    

Workaround

I found a workaround by converting the numeric ID to a string with 'node-' prefix:

editor.removeNodeId('node-' + nodeId);

This resolves the error and the node is removed as expected.

Suggestion

It would be helpful if removeNodeId could handle numeric IDs directly! Alternatively, changing the documentation to specify the expected ID format would be great.

Additional Information

  • Drawflow Version: 0.0.60
  • Browser: Chrome Version 128.0.6613.138 (Official Build) (arm64)
  • Operating System: macOS 14.1.1 (23B81)

Thank you for your time and for developing this useful library!

@jerosoler
Copy link
Owner

Hello

There is confusion with the function parameters, some are "node-x" others are just the ID.

But it is to maintain the same format as previous versions. So that there are no breaking changes.

In the description there is an example in each case:
https://github.com/jerosoler/Drawflow#methods

Regards, Jero

@ManiaMelon
Copy link
Author

Hey, thanks for the quick response, I already thought it would be something like that, makes sense :)

Maybe it would make it a bit easier for beginners if you were to add a small paragraph to the readme, maybe something like:

In Drawflow, some functions expect node IDs as "node-x" strings (e.g., "node-5"), while others use numeric IDs (e.g., 5). This is intentional to maintain compatibility with previous versions and avoid breaking changes.

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