{"action":"created","issue":{"url":"https://api.github.com/repos/deepstreamIO/deepstream.io/issues/273","repository_url":"https://api.github.com/repos/deepstreamIO/deepstream.io","labels_url":"https://api.github.com/repos/deepstreamIO/deepstream.io/issues/273/labels{/name}","comments_url":"https://api.github.com/repos/deepstreamIO/deepstream.io/issues/273/comments","events_url":"https://api.github.com/repos/deepstreamIO/deepstream.io/issues/273/events","html_url":"https://github.com/deepstreamIO/deepstream.io/issues/273","id":164710737,"number":273,"title":"dataTransform of record subscription?","user":{"login":"airguru","id":728780,"avatar_url":"https://avatars.githubusercontent.com/u/728780?v=3","gravatar_id":"","url":"https://api.github.com/users/airguru","html_url":"https://github.com/airguru","followers_url":"https://api.github.com/users/airguru/followers","following_url":"https://api.github.com/users/airguru/following{/other_user}","gists_url":"https://api.github.com/users/airguru/gists{/gist_id}","starred_url":"https://api.github.com/users/airguru/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/airguru/subscriptions","organizations_url":"https://api.github.com/users/airguru/orgs","repos_url":"https://api.github.com/users/airguru/repos","events_url":"https://api.github.com/users/airguru/events{/privacy}","received_events_url":"https://api.github.com/users/airguru/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/deepstreamIO/deepstream.io/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-07-10T11:06:36Z","updated_at":"2016-07-10T20:54:26Z","closed_at":null,"body":"Hi. I am attempting to apply dataTransform to a record that a client is subscribed to. However, as written in docs, hook to `C.ACTIONS.READ` action only catches data from the initial `.getRecord()` call. Is it possible hook into data that go through the subscription?"},"comment":{"url":"https://api.github.com/repos/deepstreamIO/deepstream.io/issues/comments/231610322","html_url":"https://github.com/deepstreamIO/deepstream.io/issues/273#issuecomment-231610322","issue_url":"https://api.github.com/repos/deepstreamIO/deepstream.io/issues/273","id":231610322,"user":{"login":"yasserf","id":2734923,"avatar_url":"https://avatars.githubusercontent.com/u/2734923?v=3","gravatar_id":"","url":"https://api.github.com/users/yasserf","html_url":"https://github.com/yasserf","followers_url":"https://api.github.com/users/yasserf/followers","following_url":"https://api.github.com/users/yasserf/following{/other_user}","gists_url":"https://api.github.com/users/yasserf/gists{/gist_id}","starred_url":"https://api.github.com/users/yasserf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yasserf/subscriptions","organizations_url":"https://api.github.com/users/yasserf/orgs","repos_url":"https://api.github.com/users/yasserf/repos","events_url":"https://api.github.com/users/yasserf/events{/privacy}","received_events_url":"https://api.github.com/users/yasserf/received_events","type":"User","site_admin":false},"created_at":"2016-07-10T20:54:26Z","updated_at":"2016-07-10T20:54:26Z","body":"This is what our documentation says ( site not yet live ):\r\n\r\nTransforming outgoing record data can be a bit complex, due to the different ways that updates are sent out.\r\n* When a client calls `client.record.getRecord( recordName )` the server responds with a READ action.\r\n* When a record is completely updated, using `record.set({})` with a single argument, an UPDATE action is sent out.\r\n* In case of partial updates, using `record.set(path, value)`, a PATCH message is sent out, containing the path and only the updated value.\r\n\r\nWhen manipulating outgoing record-data, all three cases need to be taken into account.\r\n\r\nThe following example shows how a user-discount would be applied to the price of an item, assuming:\r\n* Record names are structured as `item/<id>`\r\n* Record data looks like `{ price: <id>, other: <id> }`\r\n\r\n```javascript\r\nvar userDiscounts = {\r\n\t'anne': 0.97,\r\n\t'max': 0.90,\r\n\t'lisa': 0.85\r\n};\r\n\r\n// READ and UPDATE have the same signature,\r\n// so we can use the same function for both\r\nvar transformReadAndUpdate = function( data, metaData ) {\r\n\tif( metaData.recordName.substr( 0, 5 ) === 'item/' ) {\r\n\t\tdata.price *= userDiscounts[ metaData.receiver ];\r\n\t}\r\n\treturn data;\r\n};\r\n\r\nserver.set( 'dataTransforms', [{\r\n\ttopic: C.TOPIC.RECORD,\r\n\taction: C.ACTIONS.READ,\r\n\ttransform: transformReadAndUpdate\r\n}, {\r\n\ttopic: C.TOPIC.RECORD,\r\n\taction: C.ACTIONS.UPDATE,\r\n\ttransform: transformReadAndUpdate\r\n},{\r\n\ttopic: C.TOPIC.RECORD,\r\n\taction: C.ACTIONS.PATCH,\r\n\ttransform: function( data, metaData ) {\r\n\t\tif(\r\n\t\t\tmetaData.recordName.substr( 0, 5 ) === 'item/' &&\r\n\t\t\tmetaData.path === 'price'\r\n\t\t) {\r\n\t\t\t//data for PATCH is just the price\r\n\t\t\treturn data * userDiscounts[ metaData.receiver ];\r\n\t\t} else {\r\n\t\t\treturn data;\r\n\t\t}\r\n\t}\r\n}]);\r\n```"}}
{"actor":{"display_login":"yasserf"}}