Giter Site home page Giter Site logo

pyjamas-js's People

Contributors

danielsauve avatar davidbriglio avatar mattmaynes avatar

Watchers

 avatar  avatar  avatar

pyjamas-js's Issues

Implement Viper.toJSON

/**
 * Returns a JSON string representation of a target instance
 *
 * @param target {object} Target object to serialized
 *
 * @return {string} JSON string representation of target
 *
 * @see Viper.manifest
 */
Viper.toJSON = function(){
    ...
};

Implement Pyjamas.Version.split

/**
 * Given a string representation of a version, convert the version
 * to a 3 element array
 *
 * @param version {string} A version identifier
 *
 * @return {Array<int>} [major, minor, patch] Version array
 */
function split (version){
    ...
}

Add option to not call constructor on construct method

At times your constructor may require dependencies on other objects. Because of this if your constructor is called while these dependencies are not yet loaded, there will be issues. If an option could be made to attach the prototype and necessary attributes to the object without calling the constructor, this would be a good solution to this problem.

ie:

class MyClass {
    constructor() {
        this.test = Resource.getVal(1);
    }
}

This is a trivial example, but here we know that test is a defined value and we do not need to call the constructor to construct this object (in case Resource has not yet been defined)

Implement Pyjamas.manifest

This should be a functional implementation that takes an object and returns a deep copy of the object with an added version tag. The return should be JSON persistable (i.e. no undefined members, no functions, etc.)

/**
 * Manifests an instance of a class as a bare-bones object that confirms
 * to JavaScript Object Notation. The resulting object will have no
 * undefined fields, functions or a constructor. There are no references
 * to the original constructor stored. It is up to the user to keep the
 * association of the return the type class definition of the manifested
 * object.
 *
 * @param target {object} Target object to manifest
 *
 * @return {object} Versioned persistable representation of target
 */
Pyjamas.manifest = function (){
    ...
};

Add support for alternate versioning systems

Pyjamas currently only supports major.minor.patch versions but there are many other versioning variations available. There should be a generic way to specify a version format

Implement Pyjamas.unregister

/**
 * Removes a class from the PyjamasDB if it exists, otherwise return null
 *
 * @param constructor {function} Object constructor to unregister
 *
 * @return {Pyjamas | null} Removed Pyjamas instance or null if the constructor
 * was not registered
 * @end
 */
Pyjamas.unregister = function (){
    ...
};

Add support for multiple parent inheritance

Currently Pyjamas supports extending a single registered Pyjamas instance to have one parent. We should be able to extend multiple parents into a signal child.

Pyjamas.register(MyClassA, '0.1.0', {
    a : String,
    b : Number,
    c : Object
}).extend(MyClassB).extend(MyClassC);

Here the parent of MyClassA will only be MyClassC. We want both MyClassB and MyClassC to be parents of MyClassA.

Implement Pyjamas.register

Should register a class as a version-able instance. Should return a "Pyjamas object" or something that allows you to add version upgraders.

/**
 * Registers a class into the PyjamasDB and returns a new Pajamas instance
 *
 * @example
 * Pyjamas.register(MyClass, '0.1.2', {
 *      foo : Number,
 *      bar : String,
 *      baz : MyOtherClass
 * });
 * @end
 *
 * @param constructor   {function}  Object constructor to register
 * @param version       {string}    Current version of object constructor
 * @param defines       {object}    Definitions of instance variables to
 * persist when given an instance of the constructor's class
 * @end
 *
 * @return {Pyjamas} A new viper instance
 */
Pyjamas.register = function (){};

Error thrown from nested registered attribute that is not in json

If you try to execute Pyjamas.construct(MyObject, json) where MyObject contains another registered object, and json does not contain a reference to that object, an error is thrown at line 463 when trying to index into the object.

ie:

Pyjamas.register(MyOtherObject, '0.0.1', { z: String });
Pyjamas.register(MyObject, '0.0.1', { x: MyOtherObject, y: String });

// This will cause an error, because it will try to index into 'x' (undefined) to get values
var ob2 = Pyjamas.construct(MyObject, { y: "test" });

Error: Cannot read property 'z' of undefined

Implement Pyjamas.construct

Should accept a class constructor and a raw object which we need to use to populate a new instance of the given class. If the class has any registered "version upgraders" then they should be applied to the new instance.

/**
 * Reconstructs a persisted object as an instance of the given constructor.
 * If the given target is not at the current version of the constructor then
 * upgraders will be successively applied until the highest version is
 * achieved.
 *
 * @param constructor   {function}  Object constructor
 * @param target        {object}    Raw instance to use to populate
 * a new instance of the constructor
 * @end
 *
 * @return {object} A new instance of the constructor
 */
Pyjamas.construct = function (){
    ...
};

Implement Pyjamas.Version.diff

/**
 * Returns the difference between two version numbers. This is a
 * pairwise comparison of each element in the version identifier.
 *
 * @param base  {string} Base version
 * @param other {string} Version to compare to
 *
 * @return {Array<int>} A pairwise comparison of each version number
 */
function diff (base, other){
    ...
}

Implement Pyjamas.prototype.upgrade

/**
 * Registers an upgrade function to this viper instance. An upgrade function
 * must accept a copy of a old version of a save and the current instance.
 * It should either mutate the current instance of the save or return an
 * upgraded version.
 *
 * @param version {string} Version code that indicates the version of the
 * instance returned from this upgrade function
 * @end
 *
 * @param upgrader {function} Function to upgrade old save. Prototype:
 * function( old :  Object, current : Object) : Object
 * @end
 *
 * @return {Pyjamas} An updated Viper instance
 */
Pyjamas.prototype.upgrade = function(){
    ...
};

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.