Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-scrollmonitor",
"version": "0.1.0",
"version": "0.1.1",
"description": "Use scrollMonitor with Vue.js",
"author": "Alexandre Bonaventure <[email protected]>",
"scripts": {
Expand All @@ -11,7 +11,8 @@
"build-example": "rollup -c",
"test": "exit 0",
"version": "npm run dist && npm run build-example",
"release": "np --no-publish && npm publish"
"release": "np --no-publish && npm publish",
"prepare": "npm run dist"
},
"main": "./dist/vue-scroll-monitor.js",
"module": "./dist/vue-scroll-monitor.esm.js",
Expand Down
27 changes: 15 additions & 12 deletions src/vue-scrollmonitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const ScrollContainer = {
const $scrollMonitor = {
registerWatcher: this.registerWatcher,
unregisterWatcher: this.unregisterWatcher,
updateWatcher: this.updateWatcher,
}
Object.defineProperty($scrollMonitor, 'state', {
get : () => this.state,
Expand All @@ -27,10 +28,8 @@ export const ScrollContainer = {
data: () => ({
state: {},
}),
beforeMount () {
this.$nextTick(() => {
this.setupContainer()
})
mounted () {
this.setupContainer()
},
destroyed () {
this.teardownWatchers()
Expand All @@ -55,10 +54,10 @@ export const ScrollContainer = {
}
this.$emit('change', { ...this.state })
},
setupContainer (children) {
setupContainer () {
this._container = this.container
? scrollMonitor.createContainer(this.$el)
: scrollMonitor
? scrollMonitor.createContainer(this.$el)
: scrollMonitor
},
teardownWatchers () {
this._scrollWatchers.map(watcher => watcher.destroy())
Expand Down Expand Up @@ -115,6 +114,9 @@ export const ScrollContainer = {
})
this.$emit('change', { ...this.state })
},
recalculate () {
if (this._container) this._container.recalculateLocations()
},
log (...args) {
if (this.debug) console.log(...args)
},
Expand Down Expand Up @@ -162,9 +164,9 @@ export const ScrollItem = {
// this._scrollwatcher.lock()
// }
// },
beforeMount () {
this.$nextTick(() => {
this._scrollwatcher = this.$scrollMonitor.registerWatcher(this.id, this.$el, { offset: this.offset, lock: this.lock })
mounted () {
this.$nextTick( function () {
this._scrollwatcher = this.$scrollMonitor.registerWatcher(this.id, this.$el, { offset: this.offset, lock: this.lock })
})
},
destroyed () {
Expand All @@ -176,11 +178,11 @@ export const ScrollItem = {
}
},
watch: {
lock(val) {
lock: function (val) {
this.$scrollMonitor.updateWatcher(this.id, this.$el, { lock: val })
},
offset: {
handler() {
handler: function (val) {
this.$scrollMonitor.updateWatcher(this.id, this.$el, { offset: val })
},
deep: true,
Expand All @@ -192,3 +194,4 @@ export default {
ScrollContainer,
ScrollItem,
}