-
Notifications
You must be signed in to change notification settings - Fork 11
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
Add Evented interface (name not final) #39
Comments
Great! I can tackle this one since it looks related to my other event API task (if I'm misunderstanding, stop me here). If not, I'll start with some questions then! Going over our notes from the other day:
public interface Evented {
<T> Event<T> event(String eventName);
}
// ...
Event<Element> changeEvent = element.event("change");
Element element = changeEvent.waitUpTo(1, MINUTES);
There was also the possibility of: element.on("change"); As the API. I guess this relates to the previous question, I was taking a look at this option and was wondering how this approach would look. public interface Evented {
<T> Event<T> on(String eventName);
} Just something like that? I guess thinking about it that's more of a naming concern if it may do the same thing implementation wise. What would the Some of this discussion may go in the other issue I'm assigned so I can move that over there if it seems more relevant. |
Its actually more relevant here since the high level event api will go in On Tue, Nov 11, 2014, 9:58 AM Derek McNeil notifications@github.com wrote:
|
For now, no. I think we should treat the interface as a role based interfaced that implementation implement if they support events. If you need event support in your page object, you cast your element to
That way Button myButton = new MyButtonImpl();
assertSame(myButton, myButton.event("change").waitUpTo(1, SECONDS)); But this get's to a large discussion about what the Event should return, and I don't think it should be that.
In which case what we are expected is an event to occur so What should event return?In Javascript, event callbacks accept an event object that has various properties about the event, in addition to the target of the event. I think we should follow this pattern. This means something like: interface Evented {
Event<EventDescription> event(String eventName);
}
interface EventDescription {
// possible metadata about the event?
Element target();
} Notice that interface EventDescription<T> {
T target();
}
interface Evented<T> {
Event<EventDescription<T>> event(String eventName):
} Now EventDescriptionWhat else can go in this interface? In Javascript, the properties of an event change per event type: https://developer.mozilla.org/en-US/docs/Web/API/Event . However, if we wanted different events to return different // In darcy-ui
interface EventType<T extends EventDescription<U>, U> {
String getName();
T getDescription();
}
interface Evented<T> {
<U extends EventDescription<T>> Event<U> event(EventType<U> eventType);
}
// In something lower level
class MyTextInput implements TextInput, Evented<TextInput> {
// ...
}
class ChangeEvent implements EventType<ChangeEventDescription<T>, T extends Element> {
// ...
}
class ChangeEventDescription<T extends TextInput> {
// Hypothetical API
public String oldValue() { /* ... */ }
public String newValue() { /* .. */}
@Override public TextInput target() { /* ... */ }
}
// Usage
TextInput myInput = new MyTextInput();
Event<ChangeEventDescription<TextInput>> inputToChange = myInput.event(new ChangeEvent());
ChangeEventDescription<TextInput> eventDesc = inputToChange.waitUpTo(10, SECONDS);
assertSame(myInput, eventDesc.target()); So obviously that is pretty intense. This is why I'm not entirely sure what to do here. In the meantime, what we really want from this is to be able to wait for mutations in darcy-web, and maybe we can just side-step the higher level darcy-ui |
API like...
Event<Element> event(String eventName)
Each element type will have to override unfortunately so that Event is typed with the more specific element.
Questions:
implements Evented<String>
vsEvented<EventDescriptor>
or whatever an implementation might need)Event<Element>
?Evented<T extends Evented<T>>
to returnEvent<T>
?<T> Event<T> event(EventDesc<T> event)
The text was updated successfully, but these errors were encountered: