LaxarJS / laxar-patterns

Utilities to implement standard event patterns in LaxarJS widgets
MIT License
5 stars 2 forks source link

Add support for JSON patch format in didUpdate events #12

Closed alex3683 closed 10 years ago

alex3683 commented 10 years ago

To have a non-ambiguous format for changes of resources in the client that would even play well when communicating with a RESTful backend, we like to introduce JSON Patch (http://tools.ietf.org/html/rfc6902). For now it should only be introduced in addition to the currently supported updates and already deprecated data fields, but the goal is to make it the only supported way for didUpdate events starting from LaxarJS Patterns 1.0.

A candidate for a JSON Patch library is https://github.com/Starcounter-Jack/JSON-Patch.

alex3683 commented 10 years ago

Update information

Add json-patch to your requirejs configuration:

{
   shim: {
      // ...
      'json-patch': {
         exports: 'jsonpatch'
      }
      // ...
   },
   paths: {
      // ...
      // LaxarJS Patterns:
      'json-patch': '../bower_components/fast-json-patch/src/json-patch-duplex',
      // ...
   }
}

In your application directory delete bower_components and run

tools/bin/bower install

didUpdate-events can now carry the changes in JSON Patch syntax using the patches field. This is supported by resources.updateHandler( scope, modelKey ), resources.handlerFor( scope ) and resources.updatePublisherForFeature( scope, featurePath, optionalOptions ).

alex3683 commented 10 years ago

Implemented on master (v0.12.0)