mobx-history-api
Advanced tools
Comparing version 1.1.3 to 1.1.4
@@ -44,2 +44,3 @@ import { IComputedValue } from 'mobx'; | ||
push(url: string, position?: number | string, scrollFirst?: boolean): this; | ||
/** @deprecated - please, use addition function `scroll` from the package */ | ||
scroll(position: number | string, callback?: ScrollCallback): this; | ||
@@ -46,0 +47,0 @@ is(reg: string): boolean; |
@@ -0,1 +1,2 @@ | ||
import scroll from './scroll.es6.js'; | ||
import { __decorate } from 'tslib'; | ||
@@ -98,3 +99,3 @@ import { observable, action, computed } from 'mobx'; | ||
const { steps } = this.state; | ||
this.scroll(steps[steps.length - 1].position, () => window.history.back()); | ||
scroll(steps[steps.length - 1].position, () => window.history.back()); | ||
} | ||
@@ -136,33 +137,5 @@ else { | ||
} | ||
/** @deprecated - please, use addition function `scroll` from the package */ | ||
scroll(position, callback) { | ||
if (callback) { | ||
let top = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0; | ||
this.scroll(position); | ||
let count = 0; | ||
const interval = setInterval(() => { | ||
const currentTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0; | ||
if (currentTop === top || count++ === 30) { | ||
clearInterval(interval); | ||
callback(); | ||
} | ||
else { | ||
top = currentTop; | ||
} | ||
}, 100); | ||
} | ||
else if (typeof position === 'string') { | ||
const element = document.querySelector(position); | ||
if (element) { | ||
element.scrollIntoView(); | ||
} | ||
else { | ||
this.scroll(0); | ||
} | ||
} | ||
else if (position > -1) { | ||
const top = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0; | ||
if (top !== position) { | ||
document.documentElement.scrollTop = document.body.scrollTop = position; | ||
} | ||
} | ||
scroll(position, callback); | ||
return this; | ||
@@ -208,7 +181,7 @@ } | ||
if (scrollFirst) { | ||
this.scroll(position, mainCallback); | ||
scroll(position, mainCallback); | ||
} | ||
else { | ||
mainCallback(); | ||
this.scroll(position); | ||
scroll(position); | ||
} | ||
@@ -215,0 +188,0 @@ } |
'use strict'; | ||
var scroll = require('./scroll.js'); | ||
var tslib = require('tslib'); | ||
@@ -132,3 +133,3 @@ var mobx = require('mobx'); | ||
var steps = this.state.steps; | ||
this.scroll(steps[steps.length - 1].position, function () { return window.history.back(); }); | ||
scroll(steps[steps.length - 1].position, function () { return window.history.back(); }); | ||
} | ||
@@ -176,33 +177,5 @@ else { | ||
}; | ||
/** @deprecated - please, use addition function `scroll` from the package */ | ||
History.prototype.scroll = function (position, callback) { | ||
if (callback) { | ||
var top_1 = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0; | ||
this.scroll(position); | ||
var count_1 = 0; | ||
var interval_1 = setInterval(function () { | ||
var currentTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0; | ||
if (currentTop === top_1 || count_1++ === 30) { | ||
clearInterval(interval_1); | ||
callback(); | ||
} | ||
else { | ||
top_1 = currentTop; | ||
} | ||
}, 100); | ||
} | ||
else if (typeof position === 'string') { | ||
var element = document.querySelector(position); | ||
if (element) { | ||
element.scrollIntoView(); | ||
} | ||
else { | ||
this.scroll(0); | ||
} | ||
} | ||
else if (position > -1) { | ||
var top_2 = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0; | ||
if (top_2 !== position) { | ||
document.documentElement.scrollTop = document.body.scrollTop = position; | ||
} | ||
} | ||
scroll(position, callback); | ||
return this; | ||
@@ -253,7 +226,7 @@ }; | ||
if (scrollFirst) { | ||
this.scroll(position, mainCallback); | ||
scroll(position, mainCallback); | ||
} | ||
else { | ||
mainCallback(); | ||
this.scroll(position); | ||
scroll(position); | ||
} | ||
@@ -260,0 +233,0 @@ }; |
@@ -5,5 +5,6 @@ import decode from './decode'; | ||
import removeSearch from './removeSearch'; | ||
import scroll from './scroll'; | ||
export { default } from './history'; | ||
export * from './history'; | ||
export * from './parseUrl'; | ||
export { decode, parseUrl, setSearch, removeSearch }; | ||
export { decode, scroll, parseUrl, setSearch, removeSearch }; |
@@ -5,4 +5,5 @@ export { default as decode } from './decode.es6.js'; | ||
export { default as setSearch } from './setSearch.es6.js'; | ||
export { default as scroll } from './scroll.es6.js'; | ||
import 'tslib'; | ||
import 'mobx'; | ||
export { default } from './history.es6.js'; |
@@ -9,2 +9,3 @@ 'use strict'; | ||
var setSearch = require('./setSearch.js'); | ||
var scroll = require('./scroll.js'); | ||
require('tslib'); | ||
@@ -21,2 +22,3 @@ require('mobx'); | ||
exports.setSearch = setSearch; | ||
exports.scroll = scroll; | ||
exports.default = history; |
{ | ||
"name": "mobx-history-api", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"description": "Browser History API with Mobx", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -124,16 +124,2 @@ # mobx-history-api | ||
``` | ||
### scroll | ||
You can scroll the current page with `scroll` method of history. | ||
`scroll(position: number | string, callback?: function): this` | ||
```javascript | ||
history.scroll(100) | ||
``` | ||
If you wanna scroll the page to a defined element you can provide CSS selector to find the element and scroll to view it. | ||
```javascript | ||
history.scroll('#root') | ||
``` | ||
When you use `scroll-behavior` equals `smooth` you can get callback when the scrolling finished. | ||
```javascript | ||
history.scroll(0, () => console.log('scrolling is finished')) | ||
``` | ||
### push | ||
@@ -257,2 +243,20 @@ You can push to history any URL and you be moved forward in the history. | ||
``` | ||
### scroll | ||
You can scroll the current page with `scroll` function. | ||
`scroll(position: number | string, callback?: function): this` | ||
```javascript | ||
import {scroll} from 'mobx-history-api' | ||
scroll(100) | ||
``` | ||
If you wanna scroll the page to a defined element you can provide CSS selector to find the element and scroll to view it. | ||
```javascript | ||
import scroll from 'mobx-history-api/scroll' | ||
scroll('#root') | ||
``` | ||
When you use `scroll-behavior` equals `smooth` you can get callback when the scrolling finished. | ||
```javascript | ||
scroll(0, () => console.log('scrolling is finished')) | ||
``` | ||
## Example | ||
@@ -259,0 +263,0 @@ ```javascript |
38565
24
743
293