Git Product home page Git Product logo

Comments (5)

gaperton avatar gaperton commented on July 29, 2024

There are different design options.

  1. Link is the plain function. link() - get value, link( x ) - sets value.
getLink( name ){
    var model = this;
    return function link( x ){
         if( !arguments.length ) return model[ name ];

         model[ name ] = x;
    }
}

It's just one function with two variables closured. Not good, as combinators won't work without polluting the Function.prototype,

from nestedlink.

gaperton avatar gaperton commented on July 29, 2024
  1. Abstract class. It didn't worked with React links internals, now there won't be such a problem.
function Link(){}
Link.prototype = {
    set( x ){ throw new Error( "Not implemented" ); },
    get value(){ throw new Error( "Not implemented" ); }
}

So, in this case every object can implement specific links.

As for the model:

function ModelLink( model, attr ){
    this.model = model;
    this.attr = attr;

    // and... Yes! Pure Render.
    this._changeToken = model._changeToken;
}

ModelLink.prototype = {
    set( x ){ this.model[ this.attr ] = x; },
    get value(){ return this.model[ this.attr ]; }
}

Another option to support pure render for model links is to cache links in the model.

from nestedlink.

gaperton avatar gaperton commented on July 29, 2024

So, third caching option:

Model.prototype.getLink = function( attr ){
    var links = this._links || ( this._links = new this.Attributes() );
    return links[ attr ] || ( links[ attr ] = new Link( this, attr ) );
}

model._links should be removed on actual model change. This one should be quite efficient.

None of these things will actually help when top-level state is updated. For the links, we need to compare attribute value.

from nestedlink.

gaperton avatar gaperton commented on July 29, 2024

So, comparing the attribute value. Good thing is that in case of presence of _changeToken, prop reference check is bypassed. Which allows us just to do like this:

ModelLink.prototype = {
    set( x ){ this.model[ this.attr ] = x; },
    get value(){ return this.model[ this.attr ]; },
    get _changeToken(){ return this.value; }
}

Some bugs are possible if model or attr name will be replaced, and value will be the same. This is quite rare case, but weird. I think, we could try to live with that. At least, it's easy to implement.

from nestedlink.

gaperton avatar gaperton commented on July 29, 2024

Remove any optimization by default. That's bullshit and is too dangerous. And not needed - the full power of links on the lower level is unleashed when we use stateless components as functions, where this optimization is not possible.

Also, in new design, it will be done in Link subclasses. In NestedReact. Which is right thing to do - it knows about both models and pureRender.

from nestedlink.

Related Issues (20)

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.