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

Create adapter class for EventTarget so that it would work in older iOS. #581

Merged
merged 7 commits into from
Dec 21, 2021

Conversation

bowozer
Copy link

@bowozer bowozer commented Dec 8, 2021

It would check whether it could create EventTarget object. If failed,
then it use document object as its EventTarget object.

This is to support iOS 13 and older version.

If this needs anything else, please don't hesitate to let me know.

It would check whether it could create EventTarget object. If failed,
then it use document object as its EventTarget object.

This is to support iOS 13 and older.
@UziTech
Copy link
Collaborator

UziTech commented Dec 9, 2021

Can you write a test for this to make sure signaturePad.on('beginStroke') and other events work?

Ardhio Wibowo added 2 commits December 15, 2021 12:55
beginStroke, beforeUpdateStroke, afterUpdateStroke, endStroke events are
tested.
Added an option to use document as EventTarget

Also added test cases where using document as EventTarget.
@bowozer
Copy link
Author

bowozer commented Dec 15, 2021

Added two commits.

11286e4 contains unit tests that should have been added in PR #567, but for some reason those aren't.

40965b7 added a new option 'documentAsEventTarget' and unit tests to see whether the SignaturePad events still works if using document as EventTarget.

I hope these suffices for this to be merged.

Comment on lines 139 to 158
addEventListener(
type: string,
listener: EventListenerOrEventListenerObject | null,
options?: boolean | AddEventListenerOptions,
): void {
this._et.addEventListener(type, listener, options);
}

dispatchEvent(event: Event): boolean {
return this._et.dispatchEvent(event);
}

removeEventListener(
type: string,
callback: EventListenerOrEventListenerObject | null,
options?: boolean | EventListenerOptions,
): void {
return this._et.removeEventListener(type, callback, options);
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like these methods are copied from SignatureEventTarget wouldn't it just be easier for SignaturePad to extend SignatureEventTarget?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, you're right. Using composition over inheritance here won't get better advantage. There wouldn't be other EventTarget behaviour, would it? However when it does need it or this class needs to inherit other class, then perhaps we could implements the SignatureEventTarget, instead of extends it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yeah, i'll change this in my next commit.

@@ -37,13 +37,57 @@ export interface Options extends Partial<PointGroupOptions> {
velocityFilterWeight?: number;
backgroundColor?: string;
throttle?: number;
documentAsEventTarget?: boolean;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should pollute the options object with items used for tests.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy to remove this in my next commit. However, it wouldn't be able to be tested using document as EventTarget.

Copy link
Collaborator

@UziTech UziTech Dec 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to do something like signpad['_et'] = document to force it to be a document in the tests.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good tip, will try it right away.

}

export interface PointGroup extends PointGroupOptions {
points: BasicPoint[];
}

export default class SignaturePad extends EventTarget {
class SignatureEventTarget implements EventTarget {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this class should move to it's own file.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noted. i'm happy to change this in my next commit.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey since you're currently online, do you prefer 'signature-event-target.ts' or 'signature_event_target.ts' ? What's the convention in this project?

Ardhio Wibowo added 2 commits December 16, 2021 10:07
- remove documentAsEventTarget option
- move SignatureEventTarget class to another file
- change SignaturePad to inherit SignatureEventTarget instead of compose
  it.
@bowozer bowozer requested a review from UziTech December 16, 2021 02:24
[{ useDocument: true }, { useDocument: false }].forEach((param) => {
describe(`use document as EventTarget=${param.useDocument}.`, () => {
beforeEach(() => {
signpad['_et'] = document;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
signpad['_et'] = document;
if (param.useDocument) {
signpad['_et'] = document;
}

Copy link
Author

@bowozer bowozer Dec 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah thanks for reminding me about this. But I think I will keep implement like this, but without test parameters. Because testing with EventTarget object has been done at previous test case (above). I will provide a new commit.

@bowozer bowozer requested a review from UziTech December 16, 2021 05:26
@bowozer
Copy link
Author

bowozer commented Dec 17, 2021

@UziTech Thanks for approving this PR.

So are we (am i) done here? what's the next step?

@UziTech UziTech requested a review from szimek December 17, 2021 15:28
@UziTech
Copy link
Collaborator

UziTech commented Dec 17, 2021

Looks good to me we will try to get out a new version with this fix soon.

try {
this._et = new EventTarget();
} catch (error) {
console.warn('EventTarget object not supported, use document instead.');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! First of all, thank you so much for creating this PR!

I've got just one small issue - I'm not sure about polluting people's console with such warnings. Is it actually something that they should be aware of or can act upon? The warning says "use document", but it looks like we're doing that for them automatically already.

Maybe it would be also helpful to add a comment here that it's mostly to support Safari 13.x? Might make it easier to remove it if we ever decide to stop supporting this version.

@bowozer bowozer requested a review from szimek December 20, 2021 09:35
Copy link
Owner

@szimek szimek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much!

@UziTech UziTech merged commit 30ce9bf into szimek:master Dec 21, 2021
@github-actions
Copy link

github-actions bot commented Jan 8, 2022

🎉 This PR is included in version 4.0.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants