Comments (4)
Thanks @BlueDev. I believe that mapping functionality will be subsumed by ko.proxy
for tko, but it requires ES6; I haven't yet given much thought to incorporating something like ko.mapping for ES5 browsers.
from tko.
I haven't actually used the mapping plugin but seems a bit messy to map only the fields you want to observables in nested data structures. It seems like it would be easier to template out what the objects should look like.
Something like:
var item = ko.init({
name: null;
amount: ko.observable();
});
var options = {
makeSelfObservable: false,
map:{items:item}
}
var batch = ko.init(function(){
{
id: 0,
name: ko.observable(),
items:[{new item()}],
total: pureComputed(x => /*sum of item amounts*/)
}, options);
var x = new Batch();
Would set x to {
id: 0,
name: ko.observable(),
items:[{name:null, amount:ko.observable()}],
total: pureComputed(x => /*sum of items*/)
}
x.name("myName");
x.items[1].amount(5)
then passing in new Batch(ko.toJS(x)) would result in same structure (changed properties):
{
id: 0,
name: ko.observable("myName"),
items:[{name:null, amount:ko.observable(5)}],
total: pureComputed(x => /*sum of items*/)
}
It would probably also need a merge function with this, needing keys on the array to merge the same items.
Any thoughts from others or headaches that you experience with making certain properties observable in the model?
It seems like this would also promote putting functions relevant to sub objects in the actual object instead of most actions residing in the root view model.
It looks like a nice thing about the current mapping plugin is that logic can be added when a property is being mapped.
I am willing to work on this if people like the idea.
from tko.
Thanks @abram27 . Incidentally, what're other observable libraries e.g. mobx doing for this sort of issue?
from tko.
Looks like decorators are used for changing specific properties into observables in mobx:
https://mobx.js.org/refguide/modifiers.html
from tko.
Related Issues (20)
- Deprecate unused npm packages HOT 2
- Convert legacy documentation
- Replace hard-coded parser unicode identifier detection with RegExp HOT 3
- optionsText with a lambda value fails to resolve the function argument HOT 2
- Add preventDefault to event handler options HOT 5
- Incorrect tree with multiple 'or' operators in parser HOT 1
- Unable to load from an ES module HOT 1
- TypeError: Cannot set properties of undefined (setting 'ko') HOT 1
- Re-enable tests on builds/knockout HOT 2
- `options.bindingGlobals` can't be changed at runtime
- Revamp www.tko.io
- Fix typing of the Observable<boolean> HOT 5
- Change mappingHelpers `objectLookup` from an O(n) array to O(1) Map
- Fix the build / exports in package.json
- Build @tko/build.reference into the `tko` package
- Server side render SSR support
- How to build and import TKO-beta as a bundled library. HOT 3
- [beta1.3] ESM support HOT 3
- Writable computed out of sync
- If you have multiple || (ORs), you need parentheses, otherwise it fails silently HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tko.