Skip to content

Commit

Permalink
fix: export Drift's public API (#83)
Browse files Browse the repository at this point in the history
## Description

This PR uses [the approach preferred by the Closure docs](https://developers.google.com/closure/compiler/docs/api-tutorial3#export) to export the public API of the Drift class. This has to happen because Closure rewrites the names of the class methods, which prevents third-parties from calling methods by their proper names.

Fixes #81 

### Bug Fix

- [x] All existing unit tests are still passing (if applicable)
- [N/A] Add new passing unit tests to cover the code introduced by your PR
- [N/A] Update the readme
- [N/A] Update or add any necessary API documentation
- [x] Add some [steps](#steps-to-test) so we can test your bug fix
- [x] The PR title is in the [conventional commit](#conventional-commit-spec) format: e.g. `fix(<area>): fixed bug #issue-number`
- [x] Add your info to the [contributors](#packagejson-contributors) array in package.json!

## Steps to Test

Steps:

1.  Clone this PR, `npm install`
2. 	Run `npm run build:watch`
2.	Play around with drift in `index.html`. `console.log(new Drift(...))` should show that everything is exported on the prototype.
  • Loading branch information
frederickfogerty authored Sep 29, 2018
1 parent ac0d39a commit 82052c4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ <h1>Drift Demo</h1>
</div>
</div>

<script src="dist/Drift.min.js"></script>
<script src="dist/Drift.js"></script>
<script>
new Drift(document.querySelector('.drift-demo-trigger'), {
paneContainer: document.querySelector('.detail'),
Expand Down
19 changes: 19 additions & 0 deletions src/js/Drift.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,22 @@ export default class Drift {
this.trigger._unbindEvents();
}
}

// Public API
Object.defineProperty(Drift.prototype, "isShowing", {
get: function() {
return this.isShowing;
}
});
Object.defineProperty(Drift.prototype, "zoomFactor", {
get: function() {
return this.zoomFactor;
},
set: function(value) {
this.zoomFactor = value;
}
});
Drift.prototype["setZoomImageURL"] = Drift.prototype.setZoomImageURL;
Drift.prototype["disable"] = Drift.prototype.disable;
Drift.prototype["enable"] = Drift.prototype.enable;
Drift.prototype["destroy"] = Drift.prototype.destroy;

0 comments on commit 82052c4

Please sign in to comment.