Home

Awesome

tina-loading

:hourglass_flowing_sand: Loading plugin for Tina.js

npm license PRs Welcome

Setup

  1. Download package from npm
npm i --save @tinajs/tina-loading
  1. Install into Tina
// app.js
import Tina from '@tinajs/tina'
import loading from '@tinajs/tina-loading'

Tina.use(loading)

Usage

Normally use $loading.push() and $loading.pop() methods:

// pages/some-page.js
import { Page } from '@tinajs/tina'
import { fetchData } from '../api'
Page.define({
  async onLoad () {
    this.$loading.push()
    try {
      const data = await fetchData()
      // ...balabala
    } catch () {}
    this.$loading.pop()
  },
})

Each time calling $loading.push() method should come with one $loading.pop().

Or simply use $loading() with Promise.prototype.finally:

// pages/some-page.js
import { Page } from '@tinajs/tina'
import { fetchData } from '../api'
Page.define({
  onLoad () {
    fetchData()
      .then((data) => {
        // ...balabala
      })
      // trick here
      .finally(this.$loading())
  },
})

API

Page and Component Injections

$loading()

$loading.push()

$loading.pop()

$loading.isLoading()

License

MIT @ yelo