signal

string mixin for creating a signal.

If you found the above:

ref RestrictedSignal!(string, int) valueChanged() { return _valueChanged;}
private Signal!(string, int) _valueChanged;

a bit tedious, but still want to restrict the use of emit, you can use this string mixin. The following would result in exactly the same code:

mixin(signal!(string, int)("valueChanged"));

Additional flexibility is provided by the protection parameter, where you can change the protection of _valueChanged to protected for example.

string
signal
@trusted
(
Args...
)

Parameters

name
Type: string

How the signal should be named. The ref returning function will be named like this, the actual struct instance will have an underscore prefixed.

protection

Specifies how the full functionality (emit) of the signal should be protected. Default is private. If Protection.none is given, private is used for the Signal member variable and the ref returning accessor method will return a Signal instead of a RestrictedSignal. The protection of the accessor method is specified by the surrounding protection scope:

public: // Everyone can access mysig now:
// Result of mixin(signal!int("mysig", Protection.none))
ref Signal!int mysig() { return _mysig;}
private Signal!int _mysig;

Bugs

This mixin generator does not work with templated types right now because of: 10502
You might want to use the Signal struct directly in this case. Ideally you write the code, the mixin would generate, manually to ensure an easy upgrade path when the above bug gets fixed:

ref RestrictedSignal!(SomeTemplate!int) mysig() { return _mysig;}
private Signal!(SomeTemplate!int) _mysig;

Meta