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

Save references to services and characteristics, same as device #12

Open
danjenkins opened this issue Dec 1, 2016 · 4 comments
Open

Comments

@danjenkins
Copy link

Instead of accessing the same services and charcteristics over and over - put these references in the constructor and reference them there

@beaufortfrancois
Copy link
Owner

@danjenkins
Copy link
Author

Oh sorry, Yes - I see it as its own thing :D

@beaufortfrancois
Copy link
Owner

I see why it is tempting to cache all of them. That's what I do at https://googlechrome.github.io/samples/web-bluetooth/read-characteristic-value-changed.html

However, I also like using getPrimaryService and getCharacteristic instead as I'm sure to always get "live" services/characteristics no matter what.

@danjenkins
Copy link
Author

Hmmm, Just seems like a lot of code duplication and not ideal. By the time you add a couple more characteristics to the class, your class has a tonne of duplicate code. How would you feel about having a function that returned a promise and you'd pass the service and characteristic to the function - you'd then be able to reuse this for other characteristics (someone extending the class) and re-use it in the existing methods - meaning you could replace all of the getPrimaryService and getCharacteristic chained calls with this one function call?

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