• Components
    • Mixins

PlazarJS Core

The root type of all classes/components created in the application.
Type name: base
Properties
Name
Description
mixins: String[]
Array of defined types to be mixed into the owner component.
Methods
Name
Description
applyMixins
Applies mixins listed within mixins property.
destroy
Removes the component instance from global array.
extend (props) static
Extends the component with properties passed in as a parameter.
init internal
Initializes the component.
Root PlazarJS class. If you intend to create a class, and not a component or mixin, this is the base type you need.
Type name: class

Example usage:

        pz.define('user', { 
        
  ownerType: 'class',
  name: 'John',
  surname: 'Doe',
  sayHello: function() {
    alert('Hello, my full name is: ' + this.name + ' ' + this.surname);
  }
}).create();

// Create method invocation is not a requirement here. We use it only in case when we want to create a class immediately after defining it. We can create the class later by doing following:
// var userDef = pz.getDefinitionOf('user');
// userDef.create();

var user = pz.getInstanceOf('user');
user.sayHello();
Fiddle:

Note that create method is static and is accessible only on class type definition, not on an instance.

Root PlazarJS component. If you intend to create a component, and not a class or mixin, this is the base type you need. See components section for more details.
Type name: component

Example usage:

        var childDef = pz.define('my-child-component', { 
        
  ownerType: 'component',
  template: '<div>My first child Component!</div>',
  renderTo: 'root',
  style: 'color: red'
  // other configs
});

pz.define('my-component', {
  ownerType: 'component',
  // autoLoad: true, --- If we uncomment this line, load method invocation is not required. The component will load it self upon creation.
  template: '<div>My first Component!</div>',
  renderTo: 'body'
  // If we uncomment the components array, we do not need to add the child component dynamically. It will be added upon the parent component creation.
  // Also, declarative approach can be used in case when we have our component stored globally, otherwise, components array should contain the actual definitions.

  /*components: [{
    type: 'my-child-component'
  }]*/
  // other configs
}).create().load();

// Create method invocation is not a requirement here. We use it only in case when we want to create a component immediately after defining it.
// We can create the component later by doing the following:

// var componentDef = pz.getDefinitionOf('my-component');
// componentDef.create().load();

var myComp = pz.getInstanceOf('my-component');
// in case when we have our definition stored globally, we can use a declarative approach:
myComp.addChild({
  type: 'my-child-component'
  // other configs
});
// otherwise, we must use the actual definition as a parameter:
myComp.addChild(childDef);
Fiddle:

Note that create method is static and is accessible only on component type definition, not on an instance. Unlike load method which is and instance method.

Root PlazarJS mixin. If you intend to create a mixin, and not a component or class, this is the base type you need.
Type name: mixin

Example usage:

        pz.define('my-mixin', { 
        
  ownerType: 'mixin',
  name: 'John',
  sayHello: function() {
    alert('Hello, my name is: ' + this.name);
  }
});

pz.define('my-component', {
  ownerType: 'component',
  autoLoad: true,
  template: '<div>My first child Component!</div>',
  renderTo: 'body',
  mixins: ['my-mixin']
  // other configs
});

var componentDef = pz.getDefinitionOf('my-component');
var instance = componentDef.create();
instance.sayHello();
Fiddle:
Framework core. You can find following methods within the pz namespace
Name
Description
assignTo (target, source, clone)
  • Loops through the source object properties and clones them to the passed target object.
  • Parameters:
    • target: Object
    • source: Object
    • clone: Boolean (optional)
  • Returns: object with assigned properties.
  • Alias method: pz.obj.assignTo
create (config)
  • Creates a new component instance based on the given config. This method is also present as a static method on component definition with the difference that the static version does not require any parameters.
  • Parameters:
    • config: Object
  • Returns: created instance
  • Applicable only if the definition was previously stored within the global array. In non modular environments, this is done automatically when pz.define is invoked, otherwise you must do it yourself by invoking pz.storeDefinition if so desired. Each definition has a static method mydef.create which will produce the same output based on the provided config.
deepClone (variable)
  • Recursively loops through each property or item of the passed object or an array and copies it.
  • Parameters:
    • value: Object/[]
  • Returns: cloned item
define (type, object)
  • Defines PlazarJS framework type.
  • Parameters:
    • type: String
    • config: Object
  • Returns: defined type (definition)
  • In non modular environments, the defined item will be stored in the global array of definitions. Otherwise, you must do it yourself by invoking pz.storeDefinition if so desired.
defineApplication (config)
  • Defines an PlazarJS application, typically a single page app.
  • Parameters:
    • config: Object
  • Passed config can contain any property, but the following are recognized by the framework:
    • name: String
    • namespace: String
    • components: String
    • init: Function
defineStatic (type, object, namespace)
  • Defines PlazarJS framework static type. The type is globally defined and accessible under the passed namespace parameter (or statics if left out).
  • Parameters:
    • type: String
    • config: Object
    • namespace: Object (optional)
find (array, fn, scope)
  • Returns the first item in the array which satisfies conditions specified in the passed function (truthy return value).
  • Parameters:
    • array: Object[]
    • fn: Function
    • scope: Object (optional)
  • Returns: found item (if any)
  • Alias method: pz.arr.find
forEach (subject, fn, scope)
  • Loops through the passed collection and invokes the callback function in each iteration.
  • Parameters:
    • collection: Array
    • fn: Function
    • scope: Object (optional)
getDefinitionOf (type)
  • Retreives PlazarJS definition based on passed type.
  • Parameters:
    • type: String
  • Returns: PlazarJS definition found by passed type (if any)
  • Applicable only if the definition was previously stored within the global array. In non modular environments, this is done automatically when pz.define is invoked, otherwise you must do it yourself by invoking pz.storeDefinition if so desired.
getGlobal
Returns a global scope based on environment.
getInstanceOf (typeOrIdOrAlias, all)
  • Retreives PlazarJS component or class instance.
  • Parameters:
    • typeOrIdOrAlias: String
    • all: Boolean
  • Returns: PlazarJS instance found by passed type (if any). If the second parameter is true, all found instances are returned.
  • The first parameter should be component type, id or alias.
guid
  • Creates a new guid (globally unique identifier).
  • Returns: new guid
is (obj, ownerType)
  • Compares PlazarJS component owner type against the passed one.
  • Parameters:
    • obj: Any
    • ownerType: String
  • Returns: true/false
isArray (variable)
  • Determines if a given variable has a type of Array. Internally this method uses IsTypeOf override or isArray native function if available.
  • Parameters:
    • variable: Any
  • Returns: true/false
isClass (obj)
  • Determines if a given variable has a type of PlazarJS class. Internally this method uses is override.
  • Parameters:
    • obj: Any
  • Returns: true/false
isComponent (obj)
  • Determines if a given variable has a type of PlazarJS component. Internally this method uses is override.
  • Parameters:
    • obj: Any
  • Returns: true/false
isEmpty (variable, allowEmptyValues)
  • Determines if a given variable is empty.
  • Parameters:
    • variable: Any
    • allowEmptyValues: Boolean
  • Returns: true/false
  • Second parameter, if truthy, allows for empty string, array and object to pass the validation. This means we will have a falsy result if one of allowed values has been passed as a first parameter.
isFunction (variable)
  • Determines if a given variable has a type of Function. Internally this method uses IsTypeOf override.
  • Parameters:
    • variable: Any
  • Returns: true/false
isInstanceOf (variable, type)
  • Determines if a given variable is an instance of passed type by using native instanceof operator.
  • Parameters:
    • variable: Any
    • type: Any
  • Returns: true/false
isMixin (obj)
  • Determines if a given variable has a type of PlazarJS mixin. Internally this method uses is override.
  • Parameters:
    • obj: Any
  • Returns: true/false
isModularEnv
Checks if the environment supports modules or not.
isNodeList (variable)
  • Determines if a given variable has a type of NodeList. Internally this method uses IsTypeOf override.
  • Parameters:
    • variable: Any
  • Returns: true/false
isObject (variable)
  • Determines if a given variable has a type of Object. Internally this method uses IsTypeOf override.
  • Parameters:
    • variable: Any
  • Returns: true/false
isPzDefinition (value)
  • Checks if the given variable is a type of PlazarJS definition.
  • Parameters:
    • value: Any
  • Returns: true/false
isString (variable)
  • Determines if a given variable has a type of String. Internally this method uses IsTypeOf override.
  • Parameters:
    • variable: Any
  • Returns: true/false
isTypeOf (variable, type)
  • Compares variable type against the passed one.
  • Parameters:
    • variable: Any
    • type: String
  • Returns: true/false
ns (name, config)
  • Creates a new static namespace and applies a config to it (if any).
  • Parameters:
    • name: Any
    • config: Object (optional)
proxy (fn, context)
  • Creates a closure function with a given context.
  • Parameters:
    • fn: Function
    • context: Object
  • Returns: created proxy (closure function)
storeDefinition (type, definition)
  • Stores the defined component to the global definitions array.
  • Parameters:
    • type: String
    • definition: Function
toFunction (obj)
  • Converts a given variable to function type.
  • Parameters:
    • obj: Object
  • Returns: created function
  • This override creates a new function and sets passed object as it's prototype value.
toJSON (value, safe, asString)
  • Coverts given value to JSON type.
  • Parameters:
    • value: Function
    • safe: Boolean (optional)
    • asString: Boolean (optional)
  • Returns: created JSON
  • If the second parameter is truthy, the framework will ignore any error occured during execution and return undefined as a result. Third parameter tells the framework wheter to create a JSON object or JSON string.
toObject (obj, instantiate)
  • Converts a given variable to object type.
  • Parameters:
    • obj: Function
    • instantiate: Boolean (optional)
  • Returns: created object
  • Second parameter, if truthy, tells this override to create an object by using new keyword. Otherwise, passed function will only be invoked.