Giter VIP home page Giter VIP logo

Comments (4)

kmalakoff avatar kmalakoff commented on August 9, 2024

These look like useful helpers. Let me give some thought to the syntax...

I went with a nesting syntax for ko.DefaultObservable(obs, default_value) and put keys/requires/internals in the options or as nested options for more advanced defaults/localization. Do you think a syntax using options for static attributes is possible/desired? Similar to:

    class ContactViewModel
      constructor: (model) ->
        super(model, {keys: {
          name:     {key: 'name'}
          number:   'number'
          date:     {key:'date', localizer: kb.LongDateLocalizer}
          name2:    {key: 'name'}
        }}, @)

Please let me know what you think is a good syntax...

Cheers!

from knockback.

kmalakoff avatar kmalakoff commented on August 9, 2024

@pauljoey: one more thing. I think the cleanup code time is caused by kb.release being a bit too rigorous. There's an open bug requesting for a lighter version of kb.release (#48) which I'd like to revisit soon.

from knockback.

pauljoey avatar pauljoey commented on August 9, 2024

Just as well that it does take a while to deconstruct, it's a good indicator that I should be optimizing my knockback usage :)

The above-mentioned code structure is working great. I definitely think there's an appropriate utility to including such a feature into the Knockback core, which could be accessed via options. I think you could use the same syntax as your keys option.. call it staticKeys. It would require keys to also be specified in order to work.

I'd like to contribute when I get some time.. but I'm not optimistic about that being any time soon. Doh.

from knockback.

kmalakoff avatar kmalakoff commented on August 9, 2024

I've added statics and static_defaults to be natively supported. Here is the signature from the tests:

    view_model = new kb.ViewModel(
      new kb.Model({id: 1, name: 'Initial', date: new Date()}),
      {statics: ['name', 'author', 'description', 'tags'], static_defaults: {author: '(none)', description: null}}
    )

from knockback.

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.