Skip to content
This repository has been archived by the owner on May 23, 2022. It is now read-only.

Latest commit

 

History

History
194 lines (109 loc) · 3.87 KB

boo.rst

File metadata and controls

194 lines (109 loc) · 3.87 KB

{} boo

boo

The boo module provides primitives that abstract the semantics of prototypical object orientation, as implemented by JavaScript, such that these features can be explored with a more usable interface.

The module provides such features as the stand-alone functions: extend and derive, as well as an Object interface that can be extended upon: Base.

Internal

Interfaces

DataObject

type DataObject :: { "to_data" :: () -> Object }

Mixin

type Mixin :: Object | DataObject

Helpers

copy_property(source, target, property)

copy_property! :: Object, target:Object*, String -> target

Copies a property from source to target.

.. function:: data_obj_p(subject)

data_obj? :: Any -> Bool

Checks if the given subject matches the DataObject interface.

.. function:: resolve_mixin(object)

resolve_mixin :: Object -> Object

Returns the proper mixin for the given object.

.. function:: fast_extend(object, mixins)

fast_extend! :: target:Object*, [Mixin] -> target

Extends the target object with the provided mixins, using a right-most precedence rule — when there's a property conflict, the property defined in the last object wins.

DataObject instances are properly handled by the resolve_mixin function.

Public

Basic primitives

extend(target, mixins...)

extend!:: Object*, Mixin... -> Object

Extends the target object with the provided mixins, using a right-most precedence rule.

detail-link

+ <extend>

merge(mixins...)

merge :: Mixin... -> Object

Creates a new object that merges the provided mixins, using a right-most precedence rule.

detail-link

+ <merge>

derive(prototype, mixins...)

derive :: Object, Mixin... -> Object

Creates a new object inheriting from the given prototype and extends the new instance with the provided mixins.

detail-link

+ <derive>

Root object

object Base :: { init!  :: @this:Object*, Any... -> this
                 make   :: @this:Object, Any... -> Object <| this
                 derive :: @this:Object, Any... -> Object <| this
               }

The root object for basing all the OOP code. Provides all of Boo's primitive combinators in an easy and extensible OOP-way.

detail-link

+ <base>

Summary

-- Interface
   type DataObject :: { "to_data" :: () -> Object }
   type Mixin      :: Object | DataObject

-- Internal
   copy_property! :: Object, target:Object*, String -> target
   data_obj?      :: Any -> Bool
   resolve_mixin  :: Object -> Object
   fast_extend!   :: target:Object*, [Mixin] -> target

-- Public
   extend!     :: Object*, Mixin... -> Object
   merge       :: Mixin... -> Object
   derive      :: Object, Mixin... -> Object
   object Base :: { init!  :: @this:Object*, Any... -> this
                    make   :: @this:Object, Any... -> Object <| this
                    derive :: @this:Object, Any... -> Object <| this
                  }

extend merge derive base