Giter Club home page Giter Club logo

isometric-titanium's Introduction

Isometric Titanium

This is just a placeholder for now around some thoughts about an experimental Ti.Next API.Nothing in this repo should be considered stable, possible, eventual or likely.

Uniform Core

I'd like to re-think the Titanium API for Ti.Next. We have an opportunity with Hyperloop to create a uniform core API, something that by its very nature is isometric.

One of the big challenges that Ti.Current provides is that each implementation of the API is distinct and unique -- mostly in the implementation, but often, in the interpretation of the implementation by the developer. Even slight changes in the interpretation can create drastically different, and frustrating, bugs or errors.

I'd like to look at a layered cake approach to the Ti.Next API. Something that starts with Hyperloop at the bottom of the stack and with each stack become a little more narrow and specific and less uniform as you get to the top of the cake. So, the lower in the stack, the more broad and common.

The core would be a specified set of APIs that are required to be 100% uniform across every platform to be certified as a valid implementation. Let's call this Level 1. Each level would leverage the previous layer, much like the OSI model. Hyperloop, I suppose, could be considered Level 0.

Level 0 API

The following would be provided by the Hyperloop compiler as part of the generated code.

  • Module loading (Node.JS require, etc)
  • Memory handling (buffers, pointers, etc)
  • Native API exposure
  • Loading Third-party Libraries (such as third-party iOS Frameworks)
  • Background processing / async
  • Timers
  • Logging
  • Profiling / Debugging
  • Global scope support
  • Process API

The generated implementations would be written in 100% portable native code as part of the compilation pipeline.

Level 1 API

The Level 1 API would be 100% uniform (cross platform) and would be implemented in pure JavaScript (and possibly optimized either as part of the hyperloop distribution or during compilation).

  • Networking
  • Filesystem
  • Eventing
  • Database
  • Configuration / Properties
  • UI Layout system
  • Basic UI primitives (window, view, colors, etc)
  • Localization
  • XML

The Level 1 API would likely be the lowest level of the Ti.Next framework. These APIs would either be generated or hand written and likely would be just packaged (possibly in a special way) as modules.

Level 1 API would intentionally be small and concise. Once stable, they would likely not change. Adding APIs to this Level 1 would be done reluctantly, preferring higher Levels if possible (specifically Level 3).

Level 2 API

The Level 2 API would provide the first level of platform specialization and would provide the secondary common APIs. A good example is the secondary UI primitives common in Titanium such as Animations. The APIs would be consistently the same but the implementations would be either fully or partially supplied as part of native APIs in Hyperloop.

Level 3 API

The Level 3 API would be primarily specialized for platform specific APIs -- APIs that would never live in the levels below and would more than likely never be common. A good example of this is the UIPopover control or an Android Notification.

The Level 3 APIs could be packaged as part of the compiler toolchain to make it an experience similar to Ti.Current (i.e. feels like it is part of the Ti namespace), but would not specifically have to be part of the Ti.Next distribution.

Backwards Compatibility

First off, do we need it? Probably. Ideally. Could this be handled with a shim or a specialized pre-processor as part of the compiler pipeline?

The syntax likely should also be part of the pre-processor. For example, the following code:

var window = Ti.UI.createWindow({backgroundColor:'red'});

Could still be written by the developer, however, the compiler might pre-process to something like:

var window = new (require('ti/ui/window'))({backgroundColor:'red'});

In this way, the experience that developers currently have (and their representative code) could stay the same. The compiler would know how to pull in the appropriate modules as needed as part of the build process.

Async versus Sync

Today, the Ti.Current API is synchronous for the most part. This has provided a much more simple developer experience at the slight tradeoff in performance.

For Ti.Next, we should think hard about asynchronous APIs. We could provide a promise style way to provide an easier API for developers. We could also use the compiler to turn synchronous code into async code for execution (although, this could be itself a problem if not done well).

This is a really hot and controversial topic in the Node community and something we should really study and learn from the good and bad.

isometric-titanium's People

Contributors

cb1kenobi avatar jhaynie avatar

Stargazers

Scott Robinson avatar David Bankier avatar Flavio De Stefano avatar Pier Paolo Ramon avatar Dan Tamas avatar

Watchers

Pier Paolo Ramon avatar James Cloos avatar  avatar

isometric-titanium's Issues

Node.js compatibility

Node.js compatibility should be achieved, IMHO. The extent in which this should happen has to be defined.

Topics:

  • Follow its ES support through transpilers (see #3)
  • Shim/import/re-implement Node.js globals:
    • global (as defined by ES5)
    • process
    • Buffer
    • console
  • Shim/import/re-implement Node.js builtins

Partial implementation or shadowing (an http package that does different things than Node’s) should be avoided.

Level 1 API: JS vs C/C++

I strongly believe Layer 1 should be 100% C++. I believe that it will be much, much easier and faster to develop in C++. I suspect the runtime performance to be faster.

I suggest we use an existing framework such as libuv (https://github.com/joyent/libuv) or Poco C++ (http://pocoproject.org/).

libuv is the heart of Node.js. It's relatively portable and includes event loops, threading, filesystem, and networking support. libuv supports iOS and Android. It does not support Windows Phone 8, but it should be possible to port parts of libuv to WP.

Poco C++ is a portable library that has networking, filesystem, xml, and more. This library already supports iOS, Android, and BlackBerry. It supports Windows and Windows CE, so I imagine it wouldn't be too hard to get it running on Windows Phone. Titanium Desktop used Poco C++.

For the database, this would continue to be SQLite which is already C and runs on every mobile platform. In addition to a SQL-based database API, it's time we add a key/value database engine equivalent to IndexedDB. This would ideally be backed on LevelDB, however LevelDB does not support any Windows-based operating system.

By creating a single shared library that wraps JavaScriptCore, SQLite, and a C/C++ framework, this would produce a single cross-platform shared library for each target architecture that would speed up build times and improve developer productivity as they build Level 2 and Level 3 APIs.

Async vs sync

In Ti.Next, we should adopt ES6 promises and generators as first class citizens. Also, we should add support for the EventEmitter API from Node.js. With these tools, it will enabled cleaner, more robust, and more predictable APIs.

Most async operations should return either a promise or EventEmitter. We may even consider combining the two.

Many operations will likely need both sync and async APIs, such as filesystem and database functions.

For synchronizing async tasks, we should promote ES6 generators. It is a powerful way of making async code cleaner to read.

Obviously JavaScriptCore does not support the ES6 spec 100%. The spec isn't even finalized (though it is scheduled to be by mid-2015). To get around this, we can introduce the Traceur compiler (https://code.google.com/p/traceur-compiler/) into the build process. This allows our users to start using ES6 today.

Modules

CommonJS modules and require() exists due to the lack of a formal modules specification. In ES6, there will be a module spec.

In Ti.Next, the preferred way of loading modules would be using the import keyword and modules would export their APIs. It won't be long until ES6 modules catches on and be favored over CommonJS modules.

We still need require() to load CommonJS modules.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.