├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── package.json └── src ├── .eslintrc.json ├── index.d.ts └── index.js /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at tim@wickstrom.me. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2019 Tim Wickstrom 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VueForceNextTick 2 | 3 | > When you need to ensure the DOM has been updated Vue's nextTick just doesn't work. You will need to use the double requestAnimationFrame method. This is an elegant wrapper to allow you to use the double requestAnimationFrame method within your Vue applications either globally `Vue.$forceNextTick(callback)` or within a method `this.$forceNextTick(callback)` 4 | 5 | 6 | ## Table of contents 7 | * [VueForceNextTick](#vueforcenexttick) 8 | * [Installation](#installation) 9 | * [Default import](#default-import) 10 | * [A bit of History](#a-bit-of-history) 11 | * [Usage](#usage) 12 | * [Global Example](#global-example) 13 | * [Within a component](#within-a-component) 14 | * [Example Vue Component](#example-vue-component) 15 | 16 | ## Installation 17 | 18 | ```bash 19 | npm i vue-force-next-tick 20 | 21 | # or 22 | 23 | yarn add vue-force-next-tick 24 | ``` 25 | 26 | ## Default import 27 | ```javascript 28 | import Vue from 'vue' 29 | import VueForceNextTick from 'vue-force-next-tick' 30 | Vue.use(VueForceNextTick) 31 | ``` 32 | 33 | ## A bit of History 34 | 35 | How does [double requestanimationframe](https://stackoverflow.com/questions/44145740/how-does-double-requestanimationframe-work) work 36 | 37 | VueJS: How to wait for a browser re-render? [Vue.nextTick doesn't seem to cover it.](https://github.com/vuejs/vue/issues/9200) 38 | 39 | Inspired by the advice of [Justineo] (https://github.com/Justineo) 40 | 41 | ## Usage 42 | 43 | ### Global Example 44 | ```javascript 45 | Vue.$forceNextTick(() => { 46 | // Your code here. 47 | }) 48 | 49 | // or 50 | 51 | await Vue.$forceNextTick() 52 | ``` 53 | 54 | ### Within a component 55 | ```javascript 56 | methods: { 57 | yourMethod () { 58 | this.$forceNextTick(() => { 59 | // Your code here. 60 | }) 61 | } 62 | 63 | // or 64 | 65 | async yourMethod () { 66 | await this.$forceNextTick() 67 | // Your code here. 68 | } 69 | } 70 | ``` 71 | 72 | ### EXAMPLE VUE COMPONENT 73 | ```javascript 74 | 81 | 82 | 104 | ``` 105 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-force-next-tick", 3 | "description": "A Vue implantation of the double requestAnimationFrame method to force nextTick()", 4 | "version": "1.2.0", 5 | "author": "Tim Wickstrom ", 6 | "license": "MIT", 7 | "maintainers": [ 8 | "Tim Wickstrom (https://timwickstrom.com)" 9 | ], 10 | "contributors": [ 11 | "Tim Wickstrom ", 12 | "GU Yiling " 13 | ], 14 | "repository": { 15 | "type": "git", 16 | "url": "git+https://github.com/twickstrom/vue-force-next-tick.git" 17 | }, 18 | "bugs": { 19 | "url": "https://github.com/twickstrom/vue-force-next-tick/issues" 20 | }, 21 | "keywords": [ 22 | "vue", 23 | "vuejs", 24 | "vue.js", 25 | "vue2", 26 | "vue-force-next-tick", 27 | "nextTick", 28 | "forceNextTick", 29 | "requestAnimationFrame", 30 | "double requestAnimationFrame" 31 | ], 32 | "homepage": "https://github.com/twickstrom/vue-force-next-tick", 33 | "main": "src/index.js", 34 | "peerDependencies": { 35 | "vue": "^2.6.0 || >=3.0.0" 36 | }, 37 | "scripts": { 38 | "test": "echo \"Error: no test specified\" && exit 1" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "ignorePatterns": ["*.js"] 3 | } 4 | -------------------------------------------------------------------------------- /src/index.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'vue-force-next-tick'; 2 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | const doubleRequestAnimationFrame = (callback) => { 2 | requestAnimationFrame(() => { 3 | requestAnimationFrame(callback) 4 | }) 5 | } 6 | 7 | const forceNextTick = (callback) => { 8 | if (callback && typeof callback === 'function') { 9 | doubleRequestAnimationFrame(callback) 10 | } else { 11 | return new Promise(resolve => { 12 | doubleRequestAnimationFrame(resolve) 13 | }) 14 | } 15 | } 16 | 17 | const VueForceNextTick = { 18 | install (app) { 19 | if ('config' in app && 'globalProperties' in app.config) { 20 | app.config.globalProperties.$forceNextTick = forceNextTick 21 | } else { 22 | app.$forceNextTick = forceNextTick 23 | app.prototype.$forceNextTick = forceNextTick 24 | } 25 | } 26 | } 27 | 28 | export default VueForceNextTick 29 | --------------------------------------------------------------------------------