{"id":63,"date":"2011-01-13T17:08:51","date_gmt":"2011-01-13T17:08:51","guid":{"rendered":"http:\/\/joose.it\/blog\/?p=63"},"modified":"2011-04-08T14:00:56","modified_gmt":"2011-04-08T14:00:56","slug":"joose-3-internals-%e2%80%93-part-ii-meta-model","status":"publish","type":"post","link":"http:\/\/joose.it\/blog\/2011\/01\/13\/joose-3-internals-%e2%80%93-part-ii-meta-model\/","title":{"rendered":"Joose 3 internals \u2013 Part II. Meta-model"},"content":{"rendered":"<div>\n<div>\n<div>\n<div>\n<p>This post  will be very technical and contain a gory details about the  implementation of the meta-model in Joose. It will be useful only for  extension authors, if you are not planning to write one \u2013 nothing  interesting ahead.<\/p>\n<p>Well, you were warned.<\/p>\n<h1>Everything is a Property.<\/h1>\n<p>Property is the basement of the meta-model. It is an abstract name\/value pair.<\/p>\n<p style=\"text-align: left;\"><a href=\"..\/wp-content\/uploads\/2010\/10\/property.png\" target=\"_blank\"><\/a><a href=\"http:\/\/joose.it\/blog\/wp-content\/uploads\/2011\/01\/property.png\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-64\" style=\"border: 0pt none;\" title=\"property\" src=\"http:\/\/joose.it\/blog\/wp-content\/uploads\/2011\/01\/property.png\" alt=\"\" width=\"215\" height=\"214\" \/><\/a>Everything in Joose is a property, i.e. attribute is a property, method is a property, role\u2019s requirement is a property as well.<\/p>\n<p>As it\u2019s been mentioned in the <a href=\"..\/2010\/10\/03\/joose-3-internals-part-i-meta-layers\/\" target=\"_blank\">previous post<\/a>, property is implemented as a class from the 1st meta-level: <a href=\"http:\/\/github.com\/Joose\/Joose\/blob\/Joose3\/lib\/Joose\/Managed\/Property.js\" target=\"_blank\">Joose.Managed.Property<\/a> (it has a <a href=\"http:\/\/github.com\/Joose\/Joose\/blob\/Joose3\/lib\/Joose\/Proto\/Class.js\" target=\"_blank\">Joose.Proto.Class<\/a> as the meta-class).<\/p>\n<p>Property can be shared among several classes (via composition  relationships) so its totally self-contained and don\u2019t contain any links  to its \u201ccurrent\u201d container, only to container it was defined in.<\/p>\n<h2>Property\u2019s life stages.<\/h2>\n<p>By itself, property is just a description. To receive a concrete  implementation (one can say \u201cmaterialize\u201d property) it should be <em>applied<\/em> to target. It can be <em>un-applied<\/em> as well (remember the <a href=\"http:\/\/openjsan.org\/go\/?l=Joose.Manual.Mutability\" target=\"_blank\">mutability<\/a> feature). In general, property has the following life stages: `preApply\/apply` and `unApply\/postUnApply`.\u00a0 More on this below.<\/p>\n<h1>Everything is a PropertySet.<\/h1>\n<p><a href=\"http:\/\/github.com\/Joose\/Joose\/blob\/Joose3\/lib\/Joose\/Managed\/PropertySet.js\" target=\"_blank\">Joose.Managed.PropertySet<\/a> inherits from Joose.Managed.Property. It is an abstract, unordered collection of properties, indexed by name:<\/p>\n<p style=\"text-align: center;\"><a href=\"..\/wp-content\/uploads\/2010\/10\/property-set1.png\" target=\"_blank\"><\/a><a href=\"http:\/\/joose.it\/blog\/wp-content\/uploads\/2011\/01\/property-set.png\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-65\" style=\"border: 0pt none;\" title=\"property-set\" src=\"http:\/\/joose.it\/blog\/wp-content\/uploads\/2011\/01\/property-set.png\" alt=\"\" width=\"241\" height=\"256\" \/><\/a><\/p>\n<p>On the set of property sets (sorry for tautology) we\u2019ll define the following operations:<\/p>\n<ul>\n<li>A.cleanClone \u2013 create a \u201cclean\u201d clone of A (without any properties)<\/li>\n<li> A.clone \u2013 create a clone of A, including properties (only properties container will be cloned, not properties itself)<\/li>\n<li>A.alias(what) \u2013 add aliases for properties, listed in what<\/li>\n<li>A.exclude(what) \u2013 delete properties, listed in what<\/li>\n<li>A.flattenTo(B) \u2013 for each property in A,\n<ul>\n<li>check if the property with the same name in B exists\n<ul>\n<li>if there is one, and its a special conflict marker property or the property of A itself, then just skip it<\/li>\n<li>if there is one and its different from the above \u2013 then replace it in B with the conflict marker<\/li>\n<li>otherwise, copy that property to B<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>A.composeTo(B) \u2013 for each property a in A,\n<ul>\n<li>check if B has own property with the same name<\/li>\n<li>if not \u2013 then copy that property to B<\/li>\n<\/ul>\n<\/li>\n<li>A.composeFrom(B, C, \u2026)\n<ul>\n<li>create a clean clone of A<\/li>\n<li>flatten each argument into the clean clone (possible aliasing &amp; excluding some properties first)<\/li>\n<li>compose the result to A<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>Listed operations will implement the <a href=\"http:\/\/www.iam.unibe.ch\/%7Escg\/Research\/Traits\/\" target=\"_blank\">traits spec<\/a>. All subclasses of PropertySet will keep the semantic of these operations.<\/p>\n<h2>PropertySet\u2019s life stages.<\/h2>\n<p>PropertySet simply <a href=\"http:\/\/github.com\/Joose\/Joose\/blob\/Joose3\/lib\/Joose\/Managed\/PropertySet.js#L180\" target=\"_blank\">propagate<\/a> the `preApply\/apply\/unApply\/postUnApply` stages to its elements. Note,  that current implementation is still written in the imperative spirit  and rewriting it in more functional way will possible allow us to remove  the `unApply\/postUnApply` stages at all.<\/p>\n<h1>Mutable PropertySet.<\/h1>\n<p><a href=\"http:\/\/github.com\/Joose\/Joose\/blob\/Joose3\/lib\/Joose\/Managed\/PropertySet\/Mutable.js\" target=\"_blank\">Joose.Managed.PropertySet.Mutable<\/a> inherits from Joose.Managed.PropertySet. Its a bit more specialized  property set. It track the depended sets (derivatives) and propagate the  changes through them. Mutable set B said to be the derivative of A, if  it has been composed from A (possibly along with other sets).<\/p>\n<p>Mutable PropertySet can be in 2 states: <em>opened<\/em> (this.opened &gt; 0) &amp; <em>closed<\/em> (this.opened == 0). Mutation is only allowed when property set is <em>opened<\/em>.<\/p>\n<p>During <a href=\"http:\/\/github.com\/Joose\/Joose\/blob\/Joose3\/lib\/Joose\/Managed\/PropertySet\/Mutable.js#L97\" target=\"_blank\">\u201copen\u201d operation<\/a>, when switching from <em>closed<\/em> state to <em>opened<\/em> the set is <em>de-composed<\/em> \u2013 cleaned from all properties which weren\u2019t defined in this set. Before that all derivatives are also <em>opened<\/em>.  Note, that the set can be opened several times \u2013 subsequent \u201copen\u201ds  will be no-ops. Each \u201cclose\u201d operation  should have matching \u201copen\u201d.  Initially the set is opened (this.opened == 1)<\/p>\n<p>During <a href=\"http:\/\/github.com\/Joose\/Joose\/blob\/Joose3\/lib\/Joose\/Managed\/PropertySet\/Mutable.js#L111\" target=\"_blank\">\u201cclose\u201d operation<\/a>, when switching from <em>opened<\/em> state to <em>closed<\/em>, the set is <em>re-composed<\/em> using the data from \u201ccomposedFrom\u201d attribute and inherited \u201ccomposeFrom\u201d method.<\/p>\n<h1>Higher-order PropertySet.<\/h1>\n<p><a href=\"http:\/\/github.com\/Joose\/Joose\/blob\/Joose3\/lib\/Joose\/Managed\/PropertySet\/Composition.js\" target=\"_blank\">Joose.Managed.PropertySet.Composition<\/a> inherits from Joose.Managed.PropertySet.Mutable. Its an abstract  higher-order mutable property set \u2013 a property set, which has other  property sets as the elements:<\/p>\n<p style=\"text-align: center;\"><a href=\"..\/wp-content\/uploads\/2010\/10\/composition.png\" target=\"_blank\"><\/a><a href=\"http:\/\/joose.it\/blog\/wp-content\/uploads\/2011\/01\/composition.png\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-66\" style=\"border: 0pt none;\" title=\"composition\" src=\"http:\/\/joose.it\/blog\/wp-content\/uploads\/2011\/01\/composition.png\" alt=\"\" width=\"365\" height=\"351\" \/><\/a><\/p>\n<p>Its no longer unordered and <a href=\"http:\/\/github.com\/Joose\/Joose\/blob\/Joose3\/lib\/Joose\/Managed\/PropertySet\/Composition.js#L10\" target=\"_blank\">defines the order of properties processing<\/a> (`processOrder`), also defines <a href=\"http:\/\/github.com\/Joose\/Joose\/blob\/Joose3\/lib\/Joose\/Managed\/PropertySet\/Composition.js#L19\" target=\"_blank\">the reverse processing order<\/a>, which is important for unapplying things.<\/p>\n<h2>Composition\u2019s behavior.<\/h2>\n<p>Composition translates the higher-level operations to individual  properties. That is, when composition A is asked to be flattened to  composition B for example, it flat it\u2019s individual properties:<\/p>\n<p style=\"text-align: center;\"><a href=\"..\/wp-content\/uploads\/2010\/10\/composition-ops1.png\" target=\"_blank\"><\/a><a href=\"http:\/\/joose.it\/blog\/wp-content\/uploads\/2011\/01\/composition-ops.png\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-67\" style=\"border: 0pt none;\" title=\"composition-ops\" src=\"http:\/\/joose.it\/blog\/wp-content\/uploads\/2011\/01\/composition-ops.png\" alt=\"\" width=\"708\" height=\"323\" \/><\/a><\/p>\n<p>Other operations are defined in the same way. Note, that composition is a mutable property set.<\/p>\n<h1>Stem<\/h1>\n<p><a href=\"http:\/\/github.com\/Joose\/Joose\/blob\/Joose3\/lib\/Joose\/Managed\/Stem.js\" target=\"_blank\">Joose.Managed.Stem<\/a> inherits from Joose.Managed.PropertySet.Composition. Its a concrete implementation of composition:<\/p>\n<p style=\"text-align: center;\"><a href=\"..\/wp-content\/uploads\/2010\/10\/stem.png\" target=\"_blank\"><\/a><a href=\"http:\/\/joose.it\/blog\/wp-content\/uploads\/2011\/01\/stem.png\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-68\" style=\"border: 0pt none;\" title=\"stem\" src=\"http:\/\/joose.it\/blog\/wp-content\/uploads\/2011\/01\/stem.png\" alt=\"\" width=\"331\" height=\"313\" \/><\/a><\/p>\n<p>Stem contains the following properties (in the processing order): [  &#8216;attributes&#8217;, &#8216;methods&#8217;, &#8216;requirements&#8217;, &#8216;methodsModifiers&#8217; ]. Each of  those properties is a property set of individual properties \u2013 collection  of attributes, methods, etc.<\/p>\n<p>Stem is the first property, which is aware of the real JavaScript class it belongs to (targetMeta attribute).<\/p>\n<p><a href=\"http:\/\/github.com\/Joose\/Joose\/blob\/Joose3\/lib\/Joose\/Managed\/Stem.js#L46\" target=\"_blank\">During re-composition<\/a> stem initiates the `preApply\/apply` actions of the whole properties subtree.\u00a0 In the same way, <a href=\"http:\/\/github.com\/Joose\/Joose\/blob\/Joose3\/lib\/Joose\/Managed\/Stem.js#L57\" target=\"_blank\">during de-composition<\/a>, it initiates the `unApply\/postUnApply` stages.<\/p>\n<p>Note, that during `preApply` stage the stem is still opened, and <em>can mutate<\/em>.  During `apply` stage, the class definition is \u201cfinal\u201d and should only  be somehow \u201cmaterialized\u201d in the prototype of the class, but not  changed. The class in which the property should \u201cmaterialize\u201d itself  will be passed as the 1st argument for \u201capply\u201d method.<\/p>\n<h1>Conclusion<\/h1>\n<p>This post contains the details about the meta-model implementation in  Joose3.\u00a0 In the next post of this series we\u2019ll briefly describe the  anatomy of class from the 2nd meta-level \u2013 <a href=\"http:\/\/github.com\/Joose\/Joose\/blob\/Joose3\/lib\/Joose\/Managed\/Class.js\" target=\"_blank\">Joose.Managed.Class<\/a>.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>This post will be very technical and contain a gory details about the implementation of the meta-model in Joose. It will be useful only for extension authors, if you are not planning to write one \u2013 nothing interesting ahead. Well, you were warned. Everything is a Property. Property is the basement of the meta-model. It [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[4],"tags":[7,8],"_links":{"self":[{"href":"http:\/\/joose.it\/blog\/wp-json\/wp\/v2\/posts\/63"}],"collection":[{"href":"http:\/\/joose.it\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/joose.it\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/joose.it\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/joose.it\/blog\/wp-json\/wp\/v2\/comments?post=63"}],"version-history":[{"count":4,"href":"http:\/\/joose.it\/blog\/wp-json\/wp\/v2\/posts\/63\/revisions"}],"predecessor-version":[{"id":273,"href":"http:\/\/joose.it\/blog\/wp-json\/wp\/v2\/posts\/63\/revisions\/273"}],"wp:attachment":[{"href":"http:\/\/joose.it\/blog\/wp-json\/wp\/v2\/media?parent=63"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/joose.it\/blog\/wp-json\/wp\/v2\/categories?post=63"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/joose.it\/blog\/wp-json\/wp\/v2\/tags?post=63"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}