Skip to content

DotLabelable mechanism doesn't suit enum cases with associated values #36

Open

Description

@aufflick

The whole DotLabelable mechanism could do with a rethink - for example if your state enum cases have associated values (which mine do, and is an awesomely powerful feature of this approach) then you can't easily create the DotLabelable array (unless your associated values are something simple like strings).

Activity

  1. narfdotpl commented on Feb 8, 2017

    @narfdotpl
    Contributor

    Hi,

    I understand it can be annoying but I don't see it as a big problem: you just have to provide a value of the type you declare. I'm happy to discuss other approaches but nothing else comes to my mind given the fact that the list of items used to generate the diagram has to be passed to the actual transition logic code in order for the diagram to be always up to date.

    Here's an example from my project:

    enum Dynamic {
        case Normal
        case Gentle
    }
    
    
    enum Strength {
        case Normal
        case Strong
        case VeryStrong
    }
    
    
    enum SquareNodeEvent: DOTLabelable {
        case Highlight(delay: Double, dynamic: Dynamic, strength: Strength)
        // ...
    
        static let DOTLabelableItems = [
            Highlight(delay: 0, dynamic: .Normal, strength: .Normal),
            // ...
        ]
    
        var DOTLabel: String {
            switch self {
                case .Highlight: return "Highlight(delay, dynamic, strength)"
                default:         return "\(self)"
            }
        }
    }
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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions