Giant OOP

Giant OOP is a namespace which gives us functionality to implement oops feature using giant in our application. Following are the different component of Giant OOP

Feature:-  it is a class which implements methods to detect environment features relevant to OOP and testing. Below are the basic function that feature provide us.

  • canAssignToReadOnly Determines whether read-only properties may be covered up by assignment.
  • hasPropertyAttributes Determines whether ES5 property attributes are available.

writable:-  A flag to determine if methods are writable or not.

testing:-  A flag to determine if application is in testing mode.

Base:- This is a base class of implementing all giant classes. the methods available are.

  • addMethods Disposable method for adding further (public) methods.
  • extend Extended classes may override base class methods and properties according to regular OOP principles.
  • getTarget Determines target object of method addition.
  • getBase Retrieves the base class of the current class.
  • isA Tests whether the current class or instance is a descendant of base.
  • isBaseOf Tests whether the current class is base of the provided object.
  • instanceOf Tests whether the current class or instance is the direct extension or instance of the specified class.
  • setInstanceMapper Assigns instance key calculator to class. Makes class memoized.
  • isMemoized Tells whether the current class (or any of its base classes) is memoized.
  • clearInstanceRegistry Clears instance registry. After the registry is cleared, a new set of instances will be created for distinct constructor arguments.
  • prepareSurrogates Adds a handler to be called before evaluating any of the surrogate filters.The specified handler receives the original constructor arguments and is expected to return a modified argument list (array) that will be passed to the surrogate filters.
  • addSurrogate Adds a surrogate class to the current class. Instantiation is forwarded to the first surrogate where the filter returns true. Surrogates are processed in order of descending priority values.
  • create Creates a new instance of the class it was called on. Arguments passed to .create will be handed over to the user-defined .init method, which will decorate the new instance with properties.
  • addMethods Adds a block of public read-only methods to the class it’s called on. When $oop.testing is on, methods will be placed on the class differently than other properties, therefore it is important to use .addMethods and .addPrivateMethods for method addition.
  • addPrivateMethods Adds a block of private (non-enumerable) read-only methods to the class it’s called on. Method names must match the private prefix rule set by `$oop.privatePrefix`. When $oop.testing is on, methods will be placed on the class differently than other properties, therefore it is important to use .addMethods and .addPrivateMethods for method addition.
  • addTrait Adds a trait to the current class. A trait may be as simple as a plain object holding properties and methods to be copied over to the current class. More often however, a trait is a Giant class, through which, Giant realizes a form of multiple inheritance. There will still be just one prototype from which the current class stems, but methods delegated by the trait class will be used the same way as if they were implemented on the current class.
  • addTraitAndExtend Adds trait to current class then extends it, allowing subsequently added methods to override the trait’s methods.
  • addPublic Adds a block of public (enumerable) writable properties to the current class or instance.
  • addPrivate Adds a block of private (non-enumerable) writable properties to the current class or instance. Property names must match the private prefix rule set by `$oop.privatePrefix`.
  • addConstants Adds a block of public (enumerable) constant (read-only) properties to the current class or instance.
  • addPrivateConstants Adds a block of private (non-enumerable) constant (read-only) properties to the current class or instance. Property names must match the private prefix rule set by `$oop.privatePrefix`.
  • elevateMethod Elevates method from class level to instance level. (Or from base class to current class.) Ties context to the object it was elevated to, so methods may be safely passed as event handlers.
  • elevateMethods Elevates multiple methods. Method names are expected to be passed as individual arguments. (In no particular order.)
  • addMocks Adds a block of public (enumerable) mock methods (read-only, but removable) to the current instance or class.
  • removeMocks Removes all mock methods from the current class or instance.

Memoization:-  Below are the methods available on Memoization class

  • addInstance Adds instance to registry. Must be called on class object!
  • getInstance Fetches a memoized instance from the registry.
  • mapInstance Maps instance to registry

Surrogate:-  Implement surrogate, below are the methods available on surrogate class

  • initSurrogates Adds surrogates buffer to class
  • getSurrogate Retrieves first surrogate fitting constructor arguments.
  • surrogateDescriptorComparer Compares surrogate descriptors for sorting.

Properties:- Allows properties to be added to arbitrary objects as if they were Giant classes. The Giant base class uses these methods internally. They are exposed however due to their usefulness in testing. Below are the methods available on Properties class

  • getOwnerOf Retrieves the object from the host’s prototype chain that owns the specified property.
  • getPropertyNames Collects all property names (including non-enumerable ones) from the entire prototype chain.
  • getPropertyDescriptor Retrieves the property descriptor of the specified property regardless of its position on the prototype chain.
  • addProperty Adds single value property to the context.
  • addAccessor Adds single accessor property to the context.
  • addProperties Adds a block of properties to the context having the specified attributes.

AmendUtils:- AmendUtils class has different methods available

  • getAmendments Retrieves amendments from postponed definition.
  • setAmendments Sets amendments on postponed definition. Overwrites previous amendments.
  • addAmendment
  • applyAmendments Applies specified amendments to the specified property descriptor.

addGlobalFunctions:-  Postpones a property definition on the specified object until first access.

  • postpone Initially assigns a special getter to the property, then, when the property is accessed for the first time, the property is assigned the return value of the generator function, unless a value has been assigned from within the generator.
  • amendPostponed Applies a modifier to the postponed property to be called AFTER the property is resolved. Amendments are resolved in the order they were applied. Amendments should not expect other amendments to be applied. Amendments may be applied before the corresponding .postpone().

Below are the assertion function added by giant oops

isAllFunctions:-  Checks whether properties of `expr` are *all* functions.

isClass:- Verifies if `expr` is a Giant class.

isClassOptional:- Verifies if `expr` is a Giant class or is not defined.

isPropertyNameAvailable:- Checks whether host object has propertyName defined as its own property.

isAllPrefixed:- Checks property names against prefix.

isAccessor:- Tells whether an object holds a getter / setter pair.

isSetterGetterDescriptor:- Determines whether a property descriptor is a getter-setter.

isValueDescriptor:-  Determines whether a property descriptor is a value property.

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *