Giter Site home page Giter Site logo

coconut.ds's People

Contributors

kevinresol avatar

Stargazers

Uldis Baurovskis avatar grepsuzette avatar David Klein avatar Grabli66 avatar Marcelo Serpa avatar Juraj Kirchheim avatar  avatar

Watchers

Marcelo Serpa avatar grepsuzette avatar Juraj Kirchheim avatar James Cloos avatar  avatar David Klein avatar

coconut.ds's Issues

Editable Data

Suppose server response looks like this:

typedef UserData = {
  id:String,
  name:String,
}

then the data should provide API like this:

var user = new User({id:id, updater:<some func>});
user.refresh();
user.isInTransition.nextTime(v -> !v).handle(function(_) trace(user.name)); // 'old name'
user.update({name: 'new name'}) // use updater to send update to server
  .handle(function(o) switch o {
    case Success(_):
      // ideally this doesn't need to query the server again
      trace(user.name); // 'new name'
    case Failure(e):
  });

Prefetchable data

Basically, we use this to represent some remote data:

class User implements Model {
  @:constant var id:String;
  @:loaded var data:UserData = Server.loadUser(id);
}

var user = new User({id: 'the-id'});

But in some occasions, we have already fetched UserData from somewhere else and would like to create User from there, so that it doesn't need to load the server again.

class User implements Model {
  @:constant var id:String;
  @:constant var _data:UserData = @byDefault null;
  @:loaded var data:UserData = _data == null ? _data : Server.loadUser(id);
}

var user = new User({id: prefetchedData.id, _data: prefetchedData});

But this doesn't look very elegant. Mostly because of the two different identifiers (_data and data)

class User implements Model {
  @:constant var id:String;
  @:constant var load:String->UserData;
  @:loaded var data:UserData = load(id);
}

var user = new User({id: prefetchedData.id, load: function(id) id == prefetchedData.id ? prefetchedData : Server.loadUser(id)});

Well the above was my flow of thought. I think the desired API looks something like this:

var user = new User({id: id}); // init from id
$type(user.data); // Promised<UserData> or UserData+isInTransaction

var user = new User({data: data}); // use prefetched data
user.purge(); // kill the cache
user.data; // now it should load fresh from server

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.