bergie / VIE

Semantic Interaction Framework for JavaScript
http://viejs.org/
MIT License
303 stars 56 forks source link

Move literals handling to models and collections #114

Open bergie opened 12 years ago

bergie commented 12 years ago

Now we have two different ways to handle literals:

This difference makes for messy code. We should implement all literals in the same way, as collections of Literal objects (with subtypes like StringLiteral and UriLiteral). __toString methods should be used to allow simple usage.

This would allow setting values with:

e.set({'rdfs:label': 'Foo'});

e.set({
  'rdfs:label': new v.StringLiteral({
      value: 'Foo',
      lang: 'en'
  })
});

e.set({'rdfs:label': 'Foo'}, { lang: 'en' });

And getting with:

"" + e.get('rdfs:label'); // Foo

"" + e.get(('rdfs:label').get('en'); // Foo
neogermi commented 12 years ago

For this, we also need to add default language handling in VIE:

var v = new VIE();
v.getLang (); // the language of the document OR "en"
v.setLang("de"); // accepts language codes only in ISO 639-1 format
v.getLang(); // "de"