Why do we talk about "layers" ?

What we call a layer is nothing more than a js object structure. We gave js object that name because deepjs let you manipulate them like simple layers. Think about a software like photoshop, and how they merge layers and you almost got the concept

To illustrate it imagine a "layer" representation of your object. Let's start with a real simple object that contain one property and one function :

------ schema : un simple layer avec 2 trucs --------

Now you want to add something to your object the "layered" way. Lets see how it work :

------ schema : un simple layer avec 2 trucs + un up d'un autre layer simple qui a 2 autres trucs --------

The result of the operation is that your first layer was merged with the second, and so your object is now a composition of the 2 layers. This is a really cool way to manipulate js objects !

When you got that flat vision of your objects as layers, you could :

  • apply layers on any objects by the bottom (like a background) : use it for classic OOP (inheritance, composition).
  • or you could apply layers by the up (like a foreground) : use it to add aspects on your objects to specialise, add capabilities, modify or whatever.

------ schema : 3 layers, celui du dessous = model, du milier = implement, du dessus = Aspect --------

Tools at your disposition for manipulating layers

Your layers will rarely be as simple as the latest example, but don't worry, deepjs got all the tools to manipulate them as simple layers even if they are big or complexe as you want. For example, you don't have to use special tools to manipulate a complexe object that contains a complexe structure of nested object. Deepjs do the job as deep as your structure is. So you can always keep that representation of your js object structures as layers.

To manipulate those layers like simple sheets of paper, you got 2 basic commands :

  • up ?schema?
  • bottom ?schema?

Everything is about collision management

When you will create landscapes with your layers, you will of course get collisions of some of your layers properties/methods. By default, it is overrided with the upper layer value/function (except for arrays).

------ schema : collision de value de 2 layers + result --------

But that default behaviour is certainly not always what you want. So here again deepjs is providing all the necessary tools for managing collisions :

  • Colliders : Tools that helps you to manage the behaviour of collisions
  • Compositions : Tools to manage function collisions by composing them

Now that you have the big picture of js objects seen as layers, jump to the next section to see it in action.