Crucial Tips For Creating A Responsive Website

As I mentioned earlier, it’s the age of mobile devices nowadays. In fact, there are 6.8 billion people on the planet, 4 billion of them use a mobile phone and only 3.5 billion of them use a toothbrush.

How ridiculous it is! That’s why if your website doesn’t read well on those devices, it is possible to lose out on a huge chunk of potential customers. This is where responsive design can come into the picture and save your day nicely.

Good news is that creating a responsive website from scratch isn’t as daunting as it once was. Follow these crucial tips for a responsive site that actually works well and provides the flexibility it’s supposed to.

Keep things simple

One of the first and foremost principles to keep in mind when creating a responsive website: simplicity is the key to brilliance. Sometimes, web designers want to show off their excellence designing skills when creating a website. That’s not bad at all but when it comes to a responsive website, everything should be made as simple as possible. Also, 2016 is about minimalism and simplicity.

Remember that you are delivering the content to very limited space, there’s no room out there for you to clutter up.

Remove the unnecessary content

In order to make your responsive site really shine, simply bear one thing in mind: get rid of non-essential content. It’s not only for your user experience but also the website’s speed.

You know some content or elements of a desktop website are never meant to be used in its mobile version. Our goal is not to precisely reproduce the desktop website, but to offer the same experience to all visitors even coming in through their smartphone or their tablet.

Take the sidebar as an example, it’s a fundamental element of desktop web design, but it can clutter up the limited space of mobile screens.

Always prioritize mobile devices

Because mobile is becoming more relevant than desktop, you should always focus on the way visitors interact with your website by using their mobile phones first. Then build out your design for larger screen size. This will ensure the best possible user experience across all platforms.

Make your images flexible

Everyone already knew that one of the drawbacks of responsive design is a slow loading time. But not all of them know the main reason behind a slow site is non-optimized images. So don’t let those images drag your responsiveness down.

You can make your images flexible in a variety of ways, but one of the easiest methods is using this little handy tool: Adaptive Image

One more thing, be sure to use GIF, JPEG or PNG-8 formats to limit file sizes and help speed up the website.

Make friend with Media Queries

For those who haven’t been acquainted with media queries yet, they are a feature of CSS3 that allow content to respond to different condition on a particular device. Media queries check for a device’s resolution, height, width, and orientation. Media queries come in really handy when creating a responsive website. They are extremely simple to use as well.

Make your website readable

Nothing is more frustrating than zoom in and out, up and down, right and left to read the content. So, make sure your website legible. Visitors always want convenience, not a challenge. Your text should be large enough and comfortable to read from a smaller screen. I highly recommend a text size of 16px, 1 em or 12 pt.

Final thought

These mentioned above are just some of the more important ones you can try out. And hopefully, by now you already had some ideas of how you can use these tips for your stunning responsive website.

How to create a custom Dialog by Angular material dialog

In this post, we will go through a complete example of how to build a custom dialog by using the Angular Material Dialog component.

This covers many of the most common-used cases that of the Angular Material Dialog, such as: common dialog configuration options, dialog layout options, passing data into the dialog, and receiving data back.

With a step-by-step tutorial like this one, you should code along as we are going to start with a simple scenario. Features will be progressively added one by one along the way and detailed explanation will be provided as well.

Step 1 of 5 – Declaring a Material Dialog body component

Before we use the Angular Material Dialog, we must import MatDialogModule first:

Notice CourseDialogComponent, it will be the body of custom dialog.

In order for the component to be usable as a dialog body, we can declare it as an entryComponent, otherwise, it will appear the following error while opening the dialog:

Step 2 of 5 – Angular Material Dialog: Creating and opening

With this in place, we are now ready to create our dialog. First, we can open a dialog from one of our components:

Ok let’s see what is going on here:

  • In order to create Material Dialog instances, we are injecting the MatDialogservice via the constructor
  • Then we are creating an instance of MatDialogConfig, which will configure the dialog with a set of default behaviors
  • We are overriding a couple of those default behaviors. For example, we are setting disableClose to true, which means that the user will not be able to close the dialog just by clicking outside of it
  • We are also setting autoFocus to true, meaning that the focus will be set automatically on the first form field of the dialog

Angular Material Dialog Configuration Options

The class MatDialogConfig allows us to define a lot of configuration options. Besides the two that we have overridden, here are some other commonly used Material Dialog options:

  • hasBackdrop: defines if the dialog should have a shadow backdrop, that will blocks the user from clicking on the rest of the UI while the dialog is opened (default is true)
  • panelClass: adds a list of custom CSS classes to the Dialog panel
  • backdropClass: adds a list of custom CSS classes to the dialog backdrop
  • position: defines a starting absolute position for the dialog. For example, this would show the dialog in top left corner of the page, instead of in the center:
  • direction: this defines if the elements inside the dialog are right or left justified. The default is left-to-right (ltr), but we can also specify right-to-left (rtl).
  • closeOnNavigation: this property defines if the dialog should automatically close itself when we navigate to another route in our single page application, which defaults to true.

An example of when we would like to set this to false is the Draft Email Dialog of an Email application like Gmail, where the email draft remains opened as we search for ancient emails.
The MatDialogConfig also provides the properties width, height, minWidth, minHeight, maxWidth, and maxHeight

Step 3 of 5 – Building the Material Dialog body

Let’s now have a look at CourseDialogComponent. This is just a regular Angular component, as it does not have to inherit from any particular class or implement a dialog-specific interface.

The content of this component could also be anything, and there is no need to use any of the auxiliary Angular Material directives. We could build the body of the dialog out of plain HTML and CSS if needed.

But if we want the dialog to have the typical Material Design look and feel, we can build the template using the following directives:

Here are the 3 main directives that we used to build this dialog:

  • mat-dialog-title: This identifies the title of the dialog, in this case, the “Angular For Beginners” title on top
  • mat-dialog-content: this container will contain the body of this dialog, in this case, a reactive form
  • mat-dialog-actions: this container will contain the action buttons at the bottom of the dialog

Step 4 of 5 – Passing Input Data to the Material Dialog

Dialogs are often used to edit existing data. We can pass data to the dialog component by using the data property of the dialog configuration object.

Going back to our AppComponent, here is how we can pass some input data to the dialog:

We can then get a reference to this data object in CourseDialogComponent by using the MAT_DIALOG_DATA injectable:

As we can see, the whole data object initially passed as part of the dialog configuration object can now be directly injected into the constructor.

We have also injected something else, a reference to the dialog instance named dialogRef. We will use it to close the dialog and pass output data back to the parent component.

Step 5 of 5 – Closing The Dialog + Passing Output Data

Now that we have an editable form inside a dialog, we need a way to pass the modified (or new) data back to the parent component.

We can do via the close() method. We can call it without any arguments if we simply want to close the dialog:

But we can also pass the modified form data back to AppComponent in the following way:

In the component that created the dialog, we can now receive the dialog data in the following way:

As we can see, the call to dialog.open() returns a dialog reference, which is the same object injected in the constructor of CourseDialogComponent.

We can then use the dialog reference to subscribe to the afterClosed()observable, which will emit a value containing the output data passed to dialogRef.close().

5 JavaScript frameworks to watch

If you’ve been in the software development world over past few years, you can’t avoid noticing that JavaScript popularity continues its rising insanely. Even if you don’t have any plan on doing any web development, you will most certainly bump into JavaScript at some points on your journey. Moreover, according to IBM, JavaScript is the best programming languages to learn in 2017.
Related: What Is The Best Programming Language For Beginners?

Nonetheless, with hundreds of free JavaScript frameworks out there, you might pull your hair out to make decision which one you should get your feet wet with. If you ask five people about their choices, you will likely get five different answers. 
Everyone has their own reasons for preferring particular framework. There is no one-size-fits-all. It depends not only on how beginner-friendly is, but also what kind of projects you want to work on.

To help both you and me sleep tight at night, here are five of countless JavaScript frameworks popping up lately that are actually worth to keep an close eye on:

VUE JS

Most front-ent developers already know the big names like React, Angular and Ember. But I’d like to introduce you the less well-known but rising rapidly – Vue.js. After Vue.js 2.0 came out in April 2016 with its promise to be one of the fastest frameworks all in all, Vue.js is quickly gaining more attention.

Even though it is just a lightweight JavaScript framework, it takes the best from those big names above and putting all that into a handful tool.

You should definitely try this framework if you want to write complete applications within less than a day of reading the documentation and guide. That’s because Its source code is very readable. It allows you to easily write simple JavaScript.Vue.js is worth a look.

For more information, you can read at Vue.js website or its GitHub repository.

ANGULAR JS

What is the most beloved JavaScript framework for building single page application? What is “the big daddy” in the JavaScript framework world? Needless to say, it’s the popular Angular.

Released the first time in 2009, it was the baby of Google (which is convincing enough to use it). I know you are sick of hearing Angular.js all the time in the war of frameworks but till now, Angular ecosystem has grown beyond imagination.

Two-way data binding is a much loved feature of Angular.js because of its magic which automatically synchronizes the view and the model. Besides, it also includes some other useful features such as extending HTML vocabulary, client-side form validation, possibility to create custom DOM elements and more.
You can dive deep into it at angularjs.org.

METEOR JS

Meteor is no longer a new concept to those who study and work in IT section. Unlike other frameworks, Meteor is a smart and powerful tool that allows you build web and mobile application win one single language of JavaScript.
Related: What Is The Best Meteor.js Resource To Learn?

In term of programming, Meteor is described as an open-source and full-stack JavaScript platform that includes a key set of technologies for building reactive web and mobile applications. Meteor requires less code, so even though you are newbies to programming, you are able to build you own amazing app at lightning speed.

FYI, we are also a Prime Partner of Meteor. It was really our honor to have an opportunity for renovating their official website. You can access Meteor.com to find out how Meteor actually works in practice.

REACT JS

Are you in love with Facebook and Instagram’s users interface? Let me unveil you a secret, React.js is the super hero standing behind and powering that user interface. Isn’t it cool? Despite the fact that it is more of a library than a JS framework, it still stand out from the crowd.

Came out in 2013, it’s currently the hottest and the fastest of the bunch because of its implementation of a virtual DOM and synthetic event. Another thing developers love about React is that it’s much easier for developers with JavaScript experience to get a handle on. It’s totally not magnify to say that learning React.js is almost a must.
Find more information about React at – facebook.github.io/react/

EMBER JS

Another powerful MVC JavaScript framework is Ember.js. It was initially released in late 2011 as an open-source project by Yehuda Kats. Like Angularjs, Ember also rides on the principal of two way data binding.

Ember stands out with its simplicity and flow of functionality to make web development a smooth experience. Also, Ember community is quite big and active, so if you face any problem in your journey, you can ask them for help.
Learn more about Ember at – emberjs.com

Related: Awesome Free Resources For Learning JavaScript

Anything you would like to add?

So, there you have it. I just highlighted the 5 best JavaScript Frameworks in this blog. I hope this post can help you determine the suitable framework for your projects.

However, picking out the most suitable framework is just the beginning. It’s like you just pack you bags before going on a journey. A perfect JavaScript framework won’t make a perfect programmer if this person doesn’t make any effort. Remember, the best way to learn is by getting your hands dirty. You’ll be the best solider when you are fighting the real world enemy.

6 Reasons every Programmer has to learn JavaScript

If all the road lead to Rome, which one should you take? Wait, don’t even think about packing your bags soon if you don’t get a ticket!

Let me unveil a secret. If you are going to be a full stack ninja, JavaScript is the exactly essential ticket that you need. Even if you don’t have any plan on doing any web development, you will most certainly bump into JavaScript at some points on your journey.

If you’re unconvinced that you need to get familiar with JavaScript, I suggest that you should read my whole below reasons.

First easy step for beginner

How grateful it is to learn new thing but it’s easy to catch up on! Believe it or not, of the hundreds of programming languagesthat you could learn, none are as simple to learn as JavaScript is. It’s higher level language, which means it takes away most of complex details of the machine so your job is just focus on learning how to program.

Having fun together

JavaScript is a must learn for front-end developers. Pages without JavaScript are rather bland, whereas JavaScript laced sites allow for animation and better control over the web interface. It’s dynamic and flexible to use on object-oriented programming.

In demand

The rapidly increasing of online business makes JavaScript skills in demand for those who want to become professional programmers. Doubt it? To see it in action, open any job hunting websites, then you will see there are thousands of job announcements for programmer and software developer requiring either JavaScript directly or some JavaScript libraries such as Node.jsAngular.js, etc.

One language to rule them all

JavaScript is super versatile. Just like a dynamic kid, it runs everywhere from desktop and mobile apps, servers, databases, to even physical hardware. Especially, JavaScript is the only language built for both client-side and server-side, which makes it very fast because any code functions can be run immediately instead of having to contact the server and wait for the answer.

Besides, do you ever dream of the perspective of universal code – write once, then run everywhere? I know you do! Who doesn’t? JavaScript makes this case realizable. Once you learn JavaScript, you can use everywhere. Isn’t it amazing!

Great learning resources

Depending on your learning style, there are enormous amount of JavaScript resources out there for you to choose. A growing number of online JavaScript tutorials and classes have emerged in recent years. I highly recommend you to try CodecademyCode SchoolW3school.com.

Because you’ll have to anyway

In an environment, where the technologies and internet develop as lightning speed, website will become the future of any kinds of business. Speaking of the web, we can avoid mentioning the browsers and the browsers mean running the JavaScript. That’s why in the eyes of many experts, JavaScript is quickly becoming one of the world most popular and powerful programming language. We absolutely sure that there will be no job positions for programmers that would not have anything with JavaScript to do.

So, one way or another, you still have to learn it anyway. Why don’t you learn it now, then you will be the master in future!

Conclusion

Don’t get me wrong, JavaScript is not the only language you should ever learn, but it’s the only language that you HAVE TO learn if you want to dominate the web world. Again, no other language can take you as far if you want to do is create web application.

Now, your turn! Do you agree with my ideas? What do you think about learning JavaScript? I would love to know your thinking in the comments below.

What is the best Programming Language for Beginners?

It seems that technology rules the world these days. Then, the scene of being able to make the computer or mobile device dance to your tune seems to be very attractive. Writing computer code becomes “a super hot pot” that everyone try their best to join. However, the question is how does a person take a first step to gain this “power”? Choosing a suitable programming language might give you a hand.

To be clear, “the best” here is just relatively. It might be the best for you, but not fit for others. Everyone has their own reasons for preferring particular programming language. It depends not only on how beginner-friendly is, but also what kind of projects you want to work on.

Ruby and Ruby on Rails – The Happy Language

Ruby on rails is a great tool that can help you with the backend aspect of your programming. Although Ruby and Ruby on Rail have similar names, there’s actually an important difference: Ruby is scripting language, like Python, but Ruby on Rail is web app framework built on Ruby.

Rail is so fun for beginner because it’s really robust and it does so much of the hard work for you.
Learning to program in Ruby is much easier than other language because the language is super flexible and very forgiving, which translate to more time spend absorbing programming fundamentals, less time banging your head against your desk.

Python – The Easiest Language

When people discuss about first programming languages and which languages are easier for people to get their feet wet with, Python inevitably come up. We, programmers always desire to use as few lines of code as we can to express a concept, don’t we? Python can absolutely make it possible because of its simplicity and readability. It is usually used and referred to as a scripting language, allow programmers to churn out large quantities of codes in short periods of time.

It’s great language for beginner all the way up to seasoned professionals.

JavaScript – The Most Useful Language

There is no doubt that JavaScript is one of the world most popular and powerful programming language. It is the only language available for client-side scripting in the web development. That makes it virtually a necessity for everyone who wants to be successful as a programmer for web and a must learn for front-end developers. Pages without JavaScript are rather bland, whereas JavaScript laced sites allow for animation and better control over the web interface. It is dynamic and flexible to use on object-oriented programming.

It’s used to spice up web page by making them interactive

Get familiar with C

One thing that is importance about C: it’s one of the most foundational languages in computer science and programming. If you can grab C in your hands, other popular languages is just kids in your eyes! However, before jumping into C, you should proofread it on Wikipedia and other online resources to find out whether you should learn it or not. It’s because C requires more complex code to perform simple task, you may find it touch to keep yourself motivated if you join it as your first language.

Knowledge of C will definitely help you as programmer.

Conclusion

The nice thing is that, when you’ve taken the first step, the second step is much easier regardless of the direction it takes you. Remember, the best way to learn programming is by getting your hands dirty. You’ll be the best solider when you are fighting the real world enemy.

So, which programming language did you choose to learn first? Does it work? I would love your comments about how you became a programmer.

What is the best Meteor.js resource to learn?

People who are not programmers will surely agree with me that whether you are experienced coders or basically a shop owner who has interest in programming, you can easily learn and work on your Meteor project with minimal development effort in a short period of time.

In term of programming, Meteor is described as an open-source and full-stack JavaScript platform that includes a key set of technologies for building reactive web and mobile applications. Meteor requires less code. Instead of using thousand lines of code for a command like any other frameworks, it can just use 10 lines, Yes, 10 lines, you didn’t misread. Fantastic, right?

Since you’re here, you probably don’t know Meteor that well. Check out reasons why you should choose Meteor for your future web and mobile apps.

One more interesting thing, the Meteor community is rapidly developing day by day. That means the available resources are also growing immediately. In today’s post, I’ve rounded up the top brilliant, useful Meteor resources which could help you shorten the time you will take to learn this awesome framework from scratch.

Basic background of JavaScript

Before digging into every facet of Meteor framework, you are required to have a fairly good background of HTML, CSS and JavaScript, obviously.

  1. If your time is limited, you can take a quick look at A JavaScript Prime for Meteor
  2. If you have a little more time on your hand, you can try the tutorials at Codecademy.com or alternatively work your way through the course at JavaScript is sexy: How to learn JavaScript properly.
  3. For those who are already an advanced JavaScripter, you might want to step up your game a bit by walking through those articles at Badass JavaScript.
  4. Last but not least, don’t forget to get your hand dirty with some of the material Douglas Crockford put together before heading over to Meteor.

Meteor Resources

If you can grab JavaScript in your hands, Meteor is just kid in your eyes. I hope that the following roundup of tutorial will get you on the right track in term of learning this smart framework.

  • There is no better place to get essential information than from the official website itself: Meteor.com
  • Most importantly, check out the official Meteor documentation which contains documentation, tutorials and references.
  • FYI: Renovated by Designveloper team, Meteor.com itself is a typical example of how Meteor works in practice.
  • If you’re beginner and find their documentation bit advanced for you, you can refer to Discover Meteor which is both a website and a book written by Tom Coleman and Sacha Grief
  • The next unavoidable thing to do is head over to the Meteor Youtube channel. These videos are also very valuable if you’re starting out or want to improve your skills.
  • Check out the unofficial sanctioned wiki resource – Meteorpedia as well.
  • As a developer I believe that you have spent some time on StackOverFlow which is the perfect place to search for solution when you’re stuck with a specific problem.
  • For those who prefer watch video, you cannot avoid having a look at Evented Mind. They offer a bunch of awesome screen casts that will keep you busy for quite a while.
  • Another article worth reading is What’s This Meteor Thing? by Gabriel Manricks. I know it’s a bit outdated and old by now, but it covers a fully fledged ground in a way that no other tutorial does. If my words are not convincing enough for you, there are tons of comments left below the post showing how helpful and insightful it is for beginner Meteor developers.
  • Tom Coleman also provided a great post about Prototyping With Meteor. This particular tutorial aims to walk you through the process of turning a simple HTML wireframe into a functional application in a surprisingly simple number of step.
  • Once you decide to get your feet wet with Meteor development, it’s important to know that you understand what realtime web application is and how they work. The article, Introduction To Realtime Web Applications With Meteor And Node.js, does just that!
  • It’s time to get your hands dirty by Creating A Multi-Page Site With Meteor. In this article, the author takes a look at developing a library that not only can differentiate between the different URIs, but one that takes advantage of Meteor’s core features.
  • Learn how to Create A Meteor Chat App In 30 Minutes. What great about this tutorial is that it’s very simple to follow. Also, it gives you ideas and inspiration to work on your own stuff.

Keep up to date

Join a Meteor Meetup . If you’re in Ho Chi Minh City, don’t hesitate to swing by here and join Meteor Ho Chi Minh Meetup group. We usually meet once a month.
Subscribe to Meteor Weekly
If you prefer to listen, the Meteor Postcast might be the perfect one for you.

Know more?

So, that’s a few awesome resouces I suggest getting started with. Do you have any “I can’t believe you didn’t put it on your top” resouces? Please recommend your own tutorials by letting me know in the comments below and I will add them here. Thank you!

Single page application Development using Meteor JS

We live in a world dominated by JavaScript. Even though you are not a fan of this programming language, you still cannot ignore it if you want to be a professional developer. The good news is there are tons of JavaScript frameworks out there for you to pick up. In my case, the one that strikes my fancy the most is nothing else but Meteor.

After experimenting with this framework for a long time, one of its magical powers that I met was creating a single page app. So, in this post, we are going to discuss about benefits of single page application development using Meteor framework.

What is single page application?

If you are still wondering what single page app actually is, then read that word “single-page” again! Its name already told it all! Basically, it’s nothing but a single page without any additional pages. It is developed with an aim of improving the user experience by delivering all the functionality for an application without taking time to reload the whole page.

How about Meteor? What is Meteor?

Meteor was born in 2011 under the name Skybreak. Until January 2012, it changed to the name that we’ve called now. Unlike other frameworks, Meteor is a smart and powerful that allows you build web and mobile applications with one single language of JavaScript.

In term of programming, Meteor is describe as an open-source and full-stack JavaScript platform that includes a key set of technologies for building reactive web and mobile applications.

Benefits of single page app development in Meteor JS

There are many web frameworks available to choose from for single page web app development. But here, I’m going to bring to you a full list benefits of creating single page applications in Meteor Js.

Speed

Meteor requires less code. Instead of using thousand lines of code for a command like any other frameworks, it can just use 10 lines. Yes, 10 lines, you didn’t misread. Fantastic, right? So obviously, its speed is a outstanding benefit for developers and clients.

Responsive design

Because of the insanely increase of mobile devices, it’s a must for any kind of business to have an app that is mobile friendly. Single page apps developed with Meteor run great on desktop devices as well as on mobile devices such as smartphone, tablet, etc.

Real-time updating

When someone makes changes, data on the screen updated the moment instantly without stopping. There is no laggy feeling that is often a result of the data’s trip to the server and back.

One language

Meteor enables you to develop an awesome single page site just by only one language with one line of code which can run on both the client and the server, as well as do different things in either environment. How amazing it is! So, for those developers who want to become full-stacks ninjas, coding with Meteor framework is a good path that you cannot avoid mentioning.

Deployment

You just need only one command to push your web app to deployment and update all connected browsers and devices.

Open source

You are able to build your own amazing single page apps the way you want in a very short time. Moreover, this open source framework also owns a strong team maintain the whole projects and is responsible for new releases, QA, and keep API stable.

Because of everything mentioned above, I truly believe Meteor is one of the best frameworks out there for quickly building sing page apps, and it’s only going to get better. What do you think about it? I’d love to hear your thought in the comments below!

Multiplayer game with Unity3D and Meteor

Those who were not able to attend our 4th Meteor Ho Chi Minh meetup at September 17th could find all about Multiplayer Game with Unity3D and Meteor – one of the main topics of the meetup – in this blog.

Before digging into every facet of this post, you are required to have a fairly good background of Meteor and Unity3D.

What is Unity3D?

Unity is a cross-platform game engine developed by Unity Technologies and used to develop video games for PC, consoles, mobile devices and websites. First announced only for OS X, at Apple’s Worldwide Developers Conference in 2005, it has since been extended to target 24 platforms.

What is Meteor JS?

Meteor is a full-stack JavaScript platform for developing modern web and mobile applications. Meteor includes a key set of technologies for building connected-client reactive applications, a build tool, and a curated set of packages from the Node.js and general JavaScript community.

If you are a Meteor-novice, no worries! You can discover more about this full-stack JavaScript platform for developing single-page, real time web and mobile apps at Meteor.com

Why we should use Meteor with Unity3D?

When using Meteor, launching a MVP in 3-4 weeks can be a reality. With JavaScript on back-end, plus smart packages, Meteor allows you to develop faster. You don’t need to have experience about implement TCP/IP, UDP or pure Socket for a Gaming Server. With collection and method we can easily implement Gaming Network Architecture like Latency Compensation, Client Prediction, Server Reconciling and other technique.

How to connect MeteorJS with Unity3D

A team in Los Angeles have developed a plugin that make a bridge between Unity3D and MeteorJS through Websocket and DDP. You can find it here https://github.com/hiddenswitch/Meteor-Unity. By using this plugin we can use almost Meteor API such as: login, method, collection, publish/subscription. The plugin is great in general but one thing, it hasn’t supported WebGL for Unity3D yet.

WebGL

You cannot use hiddenswitch plugin with Unity3d WebGL now. But we can use other way to interact it. Unity3d WebGL support 2 API that help calling from inside WebGL container to javascripton page outside and reserve.

  • To call methods on GameObjects in your content from browser JavaScript, you can use the following code:

SendMessage ('MyGameObject', 'MyFunction', 'foobar');

  • To calls a function in the web page that contains the WebGL Player.

Application.ExternalCallExternalCall calls functionName in the web page containing the WebGL player, passing the given arguments to it. Supported argument types are the primitive types (string, int, float, string) and arrays of such types. Any other objects are converted to string using ToString and passed as strings.

So, did you find some great information of your own in this blog? Do you have any questions? Let me know in the comments and we can discuss about it!

Meteor Deep Dive – Reactive Programming With Tracker

Introduction

As a Meteor developer, I believe that everyone who has worked with Meteor all had experience with Tracker, or at least used it through some kinds of interfaces like getMeteordata or createContainer which come with the react-meteor-data package.

However, not all people know how Tracker works its magic. In this post, I’m going to dig into every facet of this case as well as bring to you a little bit of background knowledge.

What Is Tracker?

Tracker is a Meteor’s core package, it is small but incredibly powerful library for transparent reactive programming in Meteor.

Using Tracker you have much of the power of Functional Reactive Programming FRPsystem without following FRP’s principles when implementing your application. Combined with Tracker-aware libraries, like Session/ReactiveVar/ReactiveDict, this lets you build complex event-driven programs without writing a lot of boilerplate event-handling code.

What Make It Great?

In a nutshell, it is reactivity. In my opinion, it is the strongest aspect of Meteor. Tracker helps us make our system work reactively both on client and server with ease. We do not have to learn any extra stuffs about reactive programming or functional programming to get started.

Just read the Tracker api and do the work then the magic happens. Or even some Meteor-novice who do not know a thing about Tracker, their code still work reactively. Do you know what am I talking about? It is good old Blaze (I say it’s old because I already moved to React for all new projects).

Blaze’s helpers are reactive natively because they use Tracker inside, if you put inside them a reactive data source then whenever that source changes those helpers will be recomputed and you get new data on the screen.

Let’s read some code and behold what I am talking about, if you are already familiar with Tracker, skip this part and move to the next section to inspect the magic.

// Set up the reactive code
const counter1 = new ReactiveVar(0);
const counter2 = new ReactiveVar(0);

const observeCounter = function() {
  Tracker.autorun(function() {
    const text = `Counter1 is now: ${counter1.get()}`;
    console.warn(text);
  });
  console.warn(`Counter2 is now: ${counter2.get()}`);
};

const computation = Tracker.autorun(observeCounter);

/*
Message on the console:
Counter1 is now: 0
Counter2 is now: 0
*/

// and now change the counter1's value
counter1.set(1);
/*
Message on the console:
Counter1 is now: 1
*/

counter2.set(3);
/*
Message on the console:
Counter1 is now: 1
Counter2 is now: 3
*/

counter1.set(7);
/*
Message on the console:
Counter1 is now: 7
*/

How Does Tracker Work?

Basically Tracker is a simple interface that lets reactive data sources (like counter in the example above) talk to reactive data consumers (the observeCounter function). Below is the flow of Tracker (I ignore some good parts to make it as simple as possible)

  • Call Tracker.autorun with function F
  • If inside F, there is a reactive data source named R, then that source will add F to its dependence list
  • Then whenever the value of R changes, R will retrieve all its dependence from the dependence list and run them.

Everything is easier said than done. So, let’s take a look at the code:

const counter = new ReactiveVar(1);

  const f = function() {
    console.log(counter.get());
  };

  Tracker.autorun(f);

In the above code: counter is our reactive data source. It raises a question is that how can it know what function used inside to add that function as its dependence?

This is where the Meteor team does their trick to make this flow transparent. In fact, Tracker is an implementation of the Observer pattern or at least an Observer-liked pattern. Observer pattern can be used to create a reactive library like Tracker.

In an traditional implementation of Observer, we can think of F as an observer and R as a subject. R must have an interface to add F as its observer and notify/run F when its value changes. Something like this:

const counter = new Source();

  const f = function(val) {
    console.log(val);
  };

  counter.addObserver(f);

To imitate this, Tracker provides us these interface:

  • Tracker.autorun
  • Tracker.Dependency
  • Tracker.Dependency.prototype.depend
  • Tracker.Dependency.prototype.changed

Tracker.Dependency is the implementation of Subject in traditional Observer. All of reactive data source to use with Tracker use this object inside.

Let’s look at the basic implementation of ReactiveVar I use for examples above:

ReactiveVar = function (initialValue, equalsFunc) {
    if (! (this instanceof ReactiveVar))
      // called without `new`
      return new ReactiveVar(initialValue, equalsFunc);

    this.curValue = initialValue;
    this.equalsFunc = equalsFunc;
    this.dep = new Tracker.Dependency;
  };

  ReactiveVar.prototype.get = function () {
    if (Tracker.active)
      this.dep.depend();

    return this.curValue;
  };

  ReactiveVar.prototype.set = function (newValue) {
    var oldValue = this.curValue;

    if ((this.equalsFunc || ReactiveVar._isEqual)(oldValue, newValue))
      // value is same as last time
      return;

    this.curValue = newValue;
    this.dep.changed();
  };

So when we create a new instance of ReactiveVar, a Tracker.Dependency object will be created. This object will have two main functions: depend and changed with get call inside get and set function respectively.

This is the Tracker’s flow with more details:

Tracker.autorun will create a computation with the function (F) pass to it as the computation’s props.

// https://github.com/meteor/meteor/blob/devel/packages/tracker/tracker.js#L569-L585
  Tracker.autorun = function(f, options) {
    // ...
    var c = new Tracker.Computation(f, Tracker.currentComputation, options.onError);

    // ...

    return c;
  };

When being initiated, this computation is also set as the current computation inside a “global” variable named Tracker.currentComputation. And F will be run for the first time.

// https://github.com/meteor/meteor/blob/devel/packages/tracker/tracker.js#L146-L208
  Tracker.Computation = function(f, parent, onError) {
    // ...
    self._func = f;
    self._onError = onError;
    self._recomputing = false;

    var errored = true;
    try {
      self._compute();
      errored = false;
    } finally {
      self.firstRun = false;
      if (errored)
        self.stop();
    }
  };

  // https://github.com/meteor/meteor/blob/devel/packages/tracker/tracker.js#L302-L316
  Tracker.Computation.prototype._compute = function() {
    var self = this;
    self.invalidated = false;

    var previous = Tracker.currentComputation;
    setCurrentComputation(self);
    var previousInCompute = inCompute;
    inCompute = true;
    try {
      withNoYieldsAllowed(self._func)(self);
    } finally {
      setCurrentComputation(previous);
      inCompute = previousInCompute;
    }
  };

  // https://github.com/meteor/meteor/blob/devel/packages/tracker/tracker.js#L29-L32
  var setCurrentComputation = function(c) {
    Tracker.currentComputation = c;
    Tracker.active = !!c;
  };

If there is a .get operation (meaning .depend) inside body of F , this function will be run and set the current computation stored in the global var named Tracker.currentComputation as it’s dependent.

// https://github.com/meteor/meteor/blob/devel/packages/tracker/tracker.js#L403-L420
  Tracker.Dependency.prototype.depend = function(computation) {
    if (!computation) {
      // ...
      computation = Tracker.currentComputation;
    }
    var self = this;
    var id = computation._id;

    if (!(id in self._dependentsById)) {
      self._dependentsById[id] = computation;
      // ...
      return true;
    }
    return false;
  };

Then whenever .set is call (meaning .changed), F will be rerun

// https://github.com/meteor/meteor/blob/devel/packages/tracker/tracker.js#L428-L432
  Tracker.Dependency.prototype.changed = function() {
    var self = this;
    for (var id in self._dependentsById)
      self._dependentsById[id].invalidate();
  };

Yeah so it is the basic idea. Beyond this basic flow actually there are some other important things to be take care for to have a complete production-ready Tracker library. I am not going to write about those things, instead I will just name them. And you can go and check yourself for a deeper understanding of Tracker. They are:

  • Tracker inside Tracker (computation inside computation)
  • Clear stopped computations
  • Prevent infinite loop

Takeaways

Here’s something we’ve discovered so far:

  • Tracker make it possible to do reactive programming in Meteor
  • It is an observer-liked implementation
  • A good trick: use a “global currentComputation” to implement transparent Observer
  • Those guys who wrote Tracker are awesome 😉

So, did you find some great information of your own in this blog? I would love to know your ideas in the comments below.

Also, don’t forget to help this post spread by emailing it to a friend, or sharing it on Twitter or Facebook if you enjoyed it. Thank you!

What is the best JavaScript frameworks to learn?

If you’ve been in the software development world over past few years, you can’t avoid noticing some new versions of important JavaScript frameworks.

Although there are a variety of options for modern developers to choose from a range of JavaScript framework out there, five of them stand out: Meteor.js, Angular.js, React.js, Ember.js, Backbone.js

Meteor.js

Meteor is no longer a new concept to those who study and work in IT section. Unlike other frameworks, Meteor is a smart and powerful tool that allows you build web and mobile application win one single language of JavaScript.

In term of programming, Meteor is described as an open-source and full-stack JavaScript platform that includes a key set of technologies for building reactive web and mobile applications. Meteor requires less code, so even though you are newbies to programming, you are able to build you own amazing app at lightning speed.

You can read more about Meteor at meteor.com

Angular.js

What is the most beloved JavaScript framework for building single page application? What is “the big daddy” in the JavaScript framework world? Needless to say, it’s the popular Angular. Released the first time in 2009, it was the baby of Google (which is convincing enough to use it). Till now, Angular ecosystem has grown beyond imagination.

Two-way data binding is a much loved feature of Angular.js because of its magic which automatically synchronizes the view and the model. Besides, it also includes some other useful features such as extending HTML vocabulary, client-side form validation, possibility to create custom DOM elements and more.

Dive deep into it at angularjs.org

React.js

Are you in love with Facebook and Instagram’s users interface? Let me unveil you a secret, React.js is the super hero standing behind and powering that user interface. Isn’t it cool?

Came out in 2013, it’s currently the hottest and the fastest of the bunch because of its implementation of a virtual DOM and synthetic event. Another thing developers love about React is that it’s much easier for developers with JavaScript experience to get a handle on.

Find more information about React at – facebook.github.io/react/

Ember.js

Another powerful MVC JavaScript framework is Ember.js. It was initially released in late 2011 as an open-source project by Yehuda Kats. Like Angularjs, Ember also rides on the principal of two way data binding.

Ember stands out with its simplicity and flow of functionality to make web development a smooth experience. Also, Ember community is quite big and active, so if you face any problem in your journey, you can ask them for help.

Learn more about Ember at – emberjs.com

Backbone.js

First released in 2010 by the Jeremy Ashkenas, , Backbone is a lightweight but full featured JavaScript framework.

Backbone stands amongst some of the most popular web development framework for JavaScript developer for two reasons – it’s easy to understand usability modules, as well as the very straightforward learning curve.

You can read more about Backbone at – backbonejs.org.

So, there you have it. I just highlighted the 5 best JavaScript Frameworks in this blog. I know that choosing a JavaScript framework might be a tough choice because there are tons of frameworks available on the market these days. I hope this post can help you determine the suitable framework for your projects.

What is the best JavaScript frameworks to learn?Do you want to add some more names to the list? You can do so by mentioning the names of some more popular JavaScript frameworks in the comments box below.