Watts Kendall

Watts Kendall

1555917311

Create a Progressive Web Apps with Vue.js

Single Page Applications (SPA) are web applications that are contained in a single web page, providing a seamless navigation experience due to not having to download and parse the html for each page. Progressive Web Applications (PWA) are web applications that, using a service worker "proxy" and a manifest file, provide the necessary infrastructure to allow cashing of the application by the browser in order to be usable in poor, or no-network conditions. All modern browsers and OSes allow PWAs to be "installed" locally and, thus, provide for a native-like user experience.

A PWA is often a viable alternative to building a native application, especially for small teams, since most app stores now accept PWAs and all major OSes (Windows, Android, iOS) allow PWAs to be installed and appear on the desktop. PWAs open instantly and the browser can be directed to hide it's controls providing a native-like look and feel.

Modern tooling can simplify development but setting it up can be a time-consuming task. Let's see how to setup a SPA & PWA project. The scope of this tutorial is to describe the setup and not each framework/tools specifically - Each of these tools has extended documentation that explains how each works.

Framework & Tools

Vue

We will use the Vue ecosystem for the heavylifting:

  • Vue.js will handle our views by providing a declarative approach in defining them and seperating the code in single-file-components,
  • VueX will be used for state management
  • Vue Router will be used to handle the SPA routes

node.js

node.js will provide support for the bundling utilities and all other utilities that might be required

parcel

Parcel bundler will be used to build and bundle the application

workbox

Workbox will handle the service-worker details.

Files layout

  • ./src will contain all source code for this project.
  • ./src/web will contain the source code for the web application (the html client).
  • ./src/db (optional) will contain any database initialization scripts
  • ./src/server (optional) will contain any server-side projects
  • ./dist will contain all generated artifacts and should be ignored in git
  • ./dist/web will contain the builded and bundled web application.
  • ./dist/db (optional) will contain any artifacts generated by the database scrits
  • ./dist/server(optional) will contain any server-side projects (compiled)
  • ./.cache will be generated by parcel and should be ignored in git
  • ./node_modules will be generated by npm or parcel and should be ingored in git

The code

The code can be found in project's github repo

Javascript dependencies

Entry point (index.html)

./src/web/index.html is our entry point and just links everything together

  • <link rel="manifest" href="./manifest.webmanifest"> links the .webmanifest file
  • <div id="vueapp"></div> defines vue mounting point
  • <script src="./index.js"></script> loads the script that contains the vue application
  • navigator.serviceWorker.register('/service-worker.js'); registers the service worker script
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <link rel="manifest" href="./manifest.webmanifest">
    &lt;title&gt;Vue.js Single Page Application Template&lt;/title&gt;       
&lt;/head&gt;

&lt;body&gt;
    &lt;div id="vueapp"&gt;&lt;/div&gt;          

    &lt;script src="./index.js"&gt;&lt;/script&gt;
    &lt;script&gt;
        if ('serviceWorker' in navigator) {
            window.addEventListener('load', () =&gt; {
                navigator.serviceWorker.register('/service-worker.js');
            });
        }            
    &lt;/script&gt;
&lt;/body&gt;

</html>

Manifest

./src/web/manifest.webmanifest describes the application and is required for the application to be considered a PWA.

It’s important to maintain the .webmanifest extension for parcel compatibility.

{
“name”: “My application name”,
“short_name”: “app”,

"start_url": "/",
"background_color": "#3367D6",
"display": "standalone",
"scope": "/",
"theme_color": "#3367D6",

"icons": [
    {
        "src": "/res/app-256.png",
        "type": "image/png",
        "sizes": "256x256"
    }
]

}

Service Worker (Workbox)

./src/web/service-worker.js implements the service worker that is requred for considering the application to be a PWA. Google’s workbox is used. Workbox defines multiple stategies (network-first, cache-first, and Stale-while-revalidate). In this example all resources are served using the network-first strategy since this is the most responsice approach and maintains the capability to work offline.

console.log(“service-worker.js”)
// import service worker script
importScripts(‘https://storage.googleapis.com/workbox-cdn/releases/4.2.0/workbox-sw.js’);

// Network First
[
‘/$’, // Index
‘/', // Anything in the same host
'.+/
’ // Anything in any host
]
.forEach(mask => {
workbox.routing.registerRoute(
new RegExp(mask),
new workbox.strategies.NetworkFirst( { cacheName: ‘dynamic’ } )
);
});

Vue binding

./src/web/index.js is used to bind the vue application and our css (in scss). It imports the Vue framework, our vue application code (app.vue) and our styles (styles.scss) - All these files are located in ./src/web/ but we are using relative paths in the imports. Finally we mount our vue application to the corresponding div element.

import Vue from ‘vue’;

import App from ‘./app.vue’;
import ‘./style.scss’

new Vue(App).$mount(‘#vueapp’)

Vue Application

./src/web/app.vue contains our vue application as a single file component.

In the <template> we construct a simple navigational menu and the router-view which is the host for our single page application, all other pages are mounted in the router-view element. In this template we are using puginsteand of html.

In the <script> we import the vue framework and two custom modules, the _router.js and the _store.js and we create our vue application by extending the default vue application with the store and router modules we just loaded.

In the <style> we providing some local (scoped) styling for the menu using scss (which out bundler will convert to css)

<template lang=“pug”>
div
nav.navbar
router-link(to=“/”) home
router-link(to=“/profile”) profile
router-link(to=“/about”) about
router-view
</template>

<script>
import Vue from “vue”;
import {router} from ‘./_router.js’;
import {store} from ‘./_store.js’

export default Vue.extend({ 
    store: store,
    router: router    
});    

</script>

<style lang=“scss” scoped>

.navbar {
    text-align: center;

    * + * {
        margin-left: 8px;
    }
}

</style>

Router

./src/web/_router.js configures and initializes vue-router by loading all pages and declaring their routes.

import Vue from “vue”;

import VueRouter from ‘vue-router’;

Vue.use(VueRouter)

// 1. Import Components
import home from ‘./vues/home.vue’
import about from ‘./vues/about.vue’
import profile from ‘./vues/profile.vue’

// 2. Define some routes
const routes = [
{ path: ‘/’ , component: home },
{ path: ‘/profile’, component: profile },
{ path: ‘/about’ , component: about }
]

// 3. Create & Export the router
export const router = new VueRouter({
routes: routes
})

Store

./src/web/_store.js configures and initializes the vuex store module. It declares the global state and the available mutations. The vuex allows for global state to be modified by all view components (through the mutations) while mainting the reactivity of the framework. (ie commiting a mutation will update all components that are affected by the state change).

import Vue from ‘vue’
import Vuex from ‘vuex’;

Vue.use(Vuex);

export const store = new Vuex.Store({
state: {
name: ‘Unknown’
},

// Usege: $store.commit('mutationan', parameter)
mutations: {
    setName(state, name) {
        Vue.set(state, 'name', name);
    }
}

});

Pages

We have three pages in our example, home and about are almost identical, both are rendering the name property of the store.

profile provides an input box where the user an type his name and instantly updates the global state when the value of the input changes.

./src/web/vues/about.vue

<template lang=“pug”>
div
h1 About
p Welcome: {{$store.state.name}}
</template>

<script>
export default {

}

</script>

./src/web/vues/home.vue

<template>
<div>
<h1>Home</h1>
<p> Welcome: {{$store.state.name}}</p>

&lt;/div&gt;   

</template>

<script>
export default {
}
</script>

./src/web/profile.vue

<template lang=“pug”>
div
h1 Profile
p Welcome: {{$store.state.name}}
div.form
table
tr
td Name
td
input(:value=“$store.state.name” @input=“$store.commit(‘setName’,$event.target.value)”)
</template>

<script>
export default {

}

</script>
<style lang=“scss” scoped>
.form {
display: flex;
justify-content: center;
}
</style>

Developing

The following steps are required in order to develop on this template

  • Download or clone the code
  • Install parcel npm i -g parcel-bundler
  • Install project dependencies npm install (in project root)
  • Run the dev script npm run dev

Originally published on https://dev.to

#javascript #vue-js #web-development

What is GEEK

Buddha Community

Create a Progressive Web Apps with Vue.js

Aamir Latif

1555924346

good job, keep working

Rahim Makhani

Rahim Makhani

1625717787

Reach out to more customers: get a progressive web app

A Progressive Web App is a type of application software that is delivered through the web. It is built using standard web technologies HTML, CSS, and JavaScript. It is expected to work on any platform that uses a standards-compliant browser, including desktop and mobile.

It is also known as a type of web page or web server. With the help of these PWA web pages, you can reach more customers for a business by marketing and promoting your business through web pages. You can also gain more customers by developing PWA by hiring a progressive web app development company. Nevina Infotech is a company that can help you to build your progressive web app with the help of its enthusiastic developers.

#progressive web app development company #progressive web app developers #progressive web app platform #progressive web app development services #progressive web app development

Rahim Makhani

Rahim Makhani

1620187126

Get your Custom Progressive Web App at an affordable Price

Progressive Web App or PWA is a type of application software that is delivered over the web. It is built using standard web technologies, including HTML, CSS, and JavaScript. It is designed to work on any platform that uses a standards-compliant browser. It can work on both desktop and mobile devices.

PWA is a type of website or web page known as a web application. It doesn’t require separate bundling or distribution.

Are you searching for a progressive web app development company to develop your custom PWA at an affordable rate? Then Nevina Infotech is the best suitable choice for you. We have experienced and dedicated developers who will help you to develop your custom PWA as per your requirement.

#progressive web app development company #progressive web app developers #progressive web app platform #progressive web app development services #progressive web app development

Rahim Makhani

Rahim Makhani

1626327771

Get your custom progressive web app with the latest features

Suppose you are looking for an app that can be run on any platform, whether on a desktop or a smartphone. Progressive web app development can provide this functionality to your app. It’s made using the most common web technologies, including HTML, CSS, and JavaScript.

To get a PWA for your business requirements, you can find a progressive web app development company that can understand your vision and give you the best app that you deserve. Nevina Infotech is one of the best PWA development companies, which have the most dedicated developers with the experience of app development that can help you achieve your goals.

#progressive web app development company #progressive web app developers #progressive web app platform #progressive web app development services #progressive web app development

Top Progressive Web App Development Company in USA

AppClues Infotech is one of the leading progressive web app development company in USA. We offer the best progressive web app development & design solution to create high-performance & secure PWA.

For more info:
Website: https://www.appcluesinfotech.com/
Email: info@appcluesinfotech.com
Call: +1-978-309-9910

#top progressive web app development company in usa #hire progressive web app developers in usa #best pwa development company in usa #custom progressive web app development company #progressive web apps development #progressive web app development services

Easter  Deckow

Easter Deckow

1655630160

PyTumblr: A Python Tumblr API v2 Client

PyTumblr

Installation

Install via pip:

$ pip install pytumblr

Install from source:

$ git clone https://github.com/tumblr/pytumblr.git
$ cd pytumblr
$ python setup.py install

Usage

Create a client

A pytumblr.TumblrRestClient is the object you'll make all of your calls to the Tumblr API through. Creating one is this easy:

client = pytumblr.TumblrRestClient(
    '<consumer_key>',
    '<consumer_secret>',
    '<oauth_token>',
    '<oauth_secret>',
)

client.info() # Grabs the current user information

Two easy ways to get your credentials to are:

  1. The built-in interactive_console.py tool (if you already have a consumer key & secret)
  2. The Tumblr API console at https://api.tumblr.com/console
  3. Get sample login code at https://api.tumblr.com/console/calls/user/info

Supported Methods

User Methods

client.info() # get information about the authenticating user
client.dashboard() # get the dashboard for the authenticating user
client.likes() # get the likes for the authenticating user
client.following() # get the blogs followed by the authenticating user

client.follow('codingjester.tumblr.com') # follow a blog
client.unfollow('codingjester.tumblr.com') # unfollow a blog

client.like(id, reblogkey) # like a post
client.unlike(id, reblogkey) # unlike a post

Blog Methods

client.blog_info(blogName) # get information about a blog
client.posts(blogName, **params) # get posts for a blog
client.avatar(blogName) # get the avatar for a blog
client.blog_likes(blogName) # get the likes on a blog
client.followers(blogName) # get the followers of a blog
client.blog_following(blogName) # get the publicly exposed blogs that [blogName] follows
client.queue(blogName) # get the queue for a given blog
client.submission(blogName) # get the submissions for a given blog

Post Methods

Creating posts

PyTumblr lets you create all of the various types that Tumblr supports. When using these types there are a few defaults that are able to be used with any post type.

The default supported types are described below.

  • state - a string, the state of the post. Supported types are published, draft, queue, private
  • tags - a list, a list of strings that you want tagged on the post. eg: ["testing", "magic", "1"]
  • tweet - a string, the string of the customized tweet you want. eg: "Man I love my mega awesome post!"
  • date - a string, the customized GMT that you want
  • format - a string, the format that your post is in. Support types are html or markdown
  • slug - a string, the slug for the url of the post you want

We'll show examples throughout of these default examples while showcasing all the specific post types.

Creating a photo post

Creating a photo post supports a bunch of different options plus the described default options * caption - a string, the user supplied caption * link - a string, the "click-through" url for the photo * source - a string, the url for the photo you want to use (use this or the data parameter) * data - a list or string, a list of filepaths or a single file path for multipart file upload

#Creates a photo post using a source URL
client.create_photo(blogName, state="published", tags=["testing", "ok"],
                    source="https://68.media.tumblr.com/b965fbb2e501610a29d80ffb6fb3e1ad/tumblr_n55vdeTse11rn1906o1_500.jpg")

#Creates a photo post using a local filepath
client.create_photo(blogName, state="queue", tags=["testing", "ok"],
                    tweet="Woah this is an incredible sweet post [URL]",
                    data="/Users/johnb/path/to/my/image.jpg")

#Creates a photoset post using several local filepaths
client.create_photo(blogName, state="draft", tags=["jb is cool"], format="markdown",
                    data=["/Users/johnb/path/to/my/image.jpg", "/Users/johnb/Pictures/kittens.jpg"],
                    caption="## Mega sweet kittens")

Creating a text post

Creating a text post supports the same options as default and just a two other parameters * title - a string, the optional title for the post. Supports markdown or html * body - a string, the body of the of the post. Supports markdown or html

#Creating a text post
client.create_text(blogName, state="published", slug="testing-text-posts", title="Testing", body="testing1 2 3 4")

Creating a quote post

Creating a quote post supports the same options as default and two other parameter * quote - a string, the full text of the qote. Supports markdown or html * source - a string, the cited source. HTML supported

#Creating a quote post
client.create_quote(blogName, state="queue", quote="I am the Walrus", source="Ringo")

Creating a link post

  • title - a string, the title of post that you want. Supports HTML entities.
  • url - a string, the url that you want to create a link post for.
  • description - a string, the desciption of the link that you have
#Create a link post
client.create_link(blogName, title="I like to search things, you should too.", url="https://duckduckgo.com",
                   description="Search is pretty cool when a duck does it.")

Creating a chat post

Creating a chat post supports the same options as default and two other parameters * title - a string, the title of the chat post * conversation - a string, the text of the conversation/chat, with diablog labels (no html)

#Create a chat post
chat = """John: Testing can be fun!
Renee: Testing is tedious and so are you.
John: Aw.
"""
client.create_chat(blogName, title="Renee just doesn't understand.", conversation=chat, tags=["renee", "testing"])

Creating an audio post

Creating an audio post allows for all default options and a has 3 other parameters. The only thing to keep in mind while dealing with audio posts is to make sure that you use the external_url parameter or data. You cannot use both at the same time. * caption - a string, the caption for your post * external_url - a string, the url of the site that hosts the audio file * data - a string, the filepath of the audio file you want to upload to Tumblr

#Creating an audio file
client.create_audio(blogName, caption="Rock out.", data="/Users/johnb/Music/my/new/sweet/album.mp3")

#lets use soundcloud!
client.create_audio(blogName, caption="Mega rock out.", external_url="https://soundcloud.com/skrillex/sets/recess")

Creating a video post

Creating a video post allows for all default options and has three other options. Like the other post types, it has some restrictions. You cannot use the embed and data parameters at the same time. * caption - a string, the caption for your post * embed - a string, the HTML embed code for the video * data - a string, the path of the file you want to upload

#Creating an upload from YouTube
client.create_video(blogName, caption="Jon Snow. Mega ridiculous sword.",
                    embed="http://www.youtube.com/watch?v=40pUYLacrj4")

#Creating a video post from local file
client.create_video(blogName, caption="testing", data="/Users/johnb/testing/ok/blah.mov")

Editing a post

Updating a post requires you knowing what type a post you're updating. You'll be able to supply to the post any of the options given above for updates.

client.edit_post(blogName, id=post_id, type="text", title="Updated")
client.edit_post(blogName, id=post_id, type="photo", data="/Users/johnb/mega/awesome.jpg")

Reblogging a Post

Reblogging a post just requires knowing the post id and the reblog key, which is supplied in the JSON of any post object.

client.reblog(blogName, id=125356, reblog_key="reblog_key")

Deleting a post

Deleting just requires that you own the post and have the post id

client.delete_post(blogName, 123456) # Deletes your post :(

A note on tags: When passing tags, as params, please pass them as a list (not a comma-separated string):

client.create_text(blogName, tags=['hello', 'world'], ...)

Getting notes for a post

In order to get the notes for a post, you need to have the post id and the blog that it is on.

data = client.notes(blogName, id='123456')

The results include a timestamp you can use to make future calls.

data = client.notes(blogName, id='123456', before_timestamp=data["_links"]["next"]["query_params"]["before_timestamp"])

Tagged Methods

# get posts with a given tag
client.tagged(tag, **params)

Using the interactive console

This client comes with a nice interactive console to run you through the OAuth process, grab your tokens (and store them for future use).

You'll need pyyaml installed to run it, but then it's just:

$ python interactive-console.py

and away you go! Tokens are stored in ~/.tumblr and are also shared by other Tumblr API clients like the Ruby client.

Running tests

The tests (and coverage reports) are run with nose, like this:

python setup.py test

Author: tumblr
Source Code: https://github.com/tumblr/pytumblr
License: Apache-2.0 license

#python #api