PyJS intro

Post on 13-Jan-2015

2.672 views 0 download

Tags:

description

PyJS is a CommonJS Based Javascript Framework runs on Browser

Transcript of PyJS intro

PyJsdemixcn@gmail.com

Monday, September 19, 11

A CommonJS Based Javascript Framework

runs on Browser

https://github.com/demix/pyjs

Monday, September 19, 11

CommonJS

Monday, September 19, 11

Math.js

increment.js

program.js(main)

Monday, September 19, 11

Benifits

Monday, September 19, 11

One code , runs everywhere

No need to study and follow an ugly module pattern

Automatic namespace

Monday, September 19, 11

Browser

Server

Desktop

Command line tools

...

Monday, September 19, 11

One code , runs everywhere

No need to study and follow an ugly module pattern

Automatic namespace

Monday, September 19, 11

Traditional Module Pattern

CommonJS Module

Monday, September 19, 11

One code , runs everywhere

No need to study and follow an ugly module pattern

Automatic namespace

Monday, September 19, 11

Monday, September 19, 11

Server side Example:

NodeJS

Browser side Example:

Firefox jetpack project

Examples

Monday, September 19, 11

Problem

Monday, September 19, 11

Run directly after ‘require’.No Callback.

Monday, September 19, 11

Means in Browser, we can only use

“Synchronous”

request to get the script file.

Monday, September 19, 11

What’s the fxxk...

Monday, September 19, 11

SeaJS

Monday, September 19, 11

Monday, September 19, 11

User pre-defined template wrapper.

Prefetch Js file which has been required.

How it works

Monday, September 19, 11

Problems

Still ugly template.

Still can’t download all files in parallel

Monday, September 19, 11

PyJS

Monday, September 19, 11

Grammar

Monday, September 19, 11

99% same as CommonJS API

No ugly user pre-defined template wrapper

Monday, September 19, 11

what about the file loading problem?

You haven’t mentioned it ..

Monday, September 19, 11

There is two loading rules in PyJS.

One in local debugging,

the other in online building.

All need Python environment.

Monday, September 19, 11

python pyjs.py runserver

Fetch the JS file in synchronous XHR request.

Server will parse the module file automaticly

Local debugging

Monday, September 19, 11

Server parse

Monday, September 19, 11

Online buildingpython pyjs.py

Automaticly generate a ‘boot.js’ file, find all the dependences in modules and add the information to the end of boot.js file.

Monday, September 19, 11

Then , if we had a combo service like:

Monday, September 19, 11

We can download the file just in one

request!

Monday, September 19, 11

Finally , because of the require function used on page has a callback, it can runs after all the files

is received and finish excuting.

Monday, September 19, 11

That’s all.

Monday, September 19, 11

More..

Monday, September 19, 11

Because we use python...

Local transmission

Local plugins

Deal with CSS files.

...

Monday, September 19, 11

demixFront-end engineer @ Baidu co.

email: demixcn@gmail.com

weibo/twitter: @demix

Homepage: http://demix.github.com/

blog: http://www.cnblogs.com/demix

Monday, September 19, 11

Thank You.

Monday, September 19, 11