Comments (4)
@jameslaneconkling sorry for the delay, I didn't have notifications turned on for the repo.
Yes, you can access the deref'd path from the output JSON via the $__path
key. So in your example, you can get it from userModel.$__path
.
I've been going back and forth on whether to move the $__ props to a public namespace or not. So far, I've only had to use them in library-internals, so I've kept them $__. Thoughts?
from falcor.
@trxcllnt ah excellent, $__path
is exactly what I was looking for. Specifically, if I make a get or call request with refs in the response, I can get the absolute paths for those nodes via something like (in my case) falcorJSON.json.search.<searchId>.matches.<searchResultIdx>.$__path
.
Just thinking as I go here, but I'd guess there are at least as many good reasons for keeping this out of the public namespace, as there are for exposing it. The more common case for an end user, I'd guess, would be navigating through/iterating over the result data and ignoring metadata like $__path
. But for cases where you are interested in the absolute/dereferenced path, $__path
works, and b/c it's not enumerable, a user doesn't have to worry about accidentally iterating over it.
I vaguely remember a conversation on the Netflix falcor issue tracker about accessing or filtering out graph metadata, so that if you're iterating through your falcorJSON
response, you don't have to worry about manually avoiding node metadata.
On a related note, are there available ways to iterate over a falcorJSON
result set? B/c it's not a POJO, utils like R.map
don't work, and Object.keys(falcorJSON)
returns the f_meta
key. It appears it does inherit methods from the Array prototype (from here?), but they don't work as expected, e.g. falcorJSON.map(x => x)
always returns an empty array.
from falcor.
I vaguely remember a conversation on the Netflix falcor issue tracker about accessing or filtering out graph metadata, so that if you're iterating through your falcorJSON response, you don't have to worry about manually avoiding node metadata.
Yeah, there aren't a lot of good options here. Falcor needs the JSON to have some metadata to know how to deref new Models, but we also don't want to pollute the output namespace too much. In the new mutable cache walk, I can get away with creating a second prototype Object and sticking the metadata on there, because the sub-tree diff'ing we get via hashcodes makes get so fast in the 80% case, we have a ton of breathing room to do extra allocations.
Alternatively, I've added support for a new branchSelector
function, which will be called with the FalcorJSON
instance as each branch is created. The JSON argument will already have the metadata attached, so you can use it as the prototype for your own instances if you want. You can define it once when you create the root Model (via new Model({ branchSelector: (json) => /* do your thing */ })
.
On a related note, are there available ways to iterate over a falcorJSON result set? B/c it's not a POJO, utils like R.map don't work, and Object.keys(falcorJSON) returns the f_meta key. It appears it does inherit methods from the Array prototype (from here?), but they don't work as expected, e.g. falcorJSON.map(x => x) always returns an empty array.
So this is my probably-too-clever solution to make it easier to work with lists. If you request a range of integers along with the length, we can use the native Array methods on the JSON result. This is especially handy when combined with the falcor-react-schema/withFragment
higher-order component (still a work-in-progress port to separate the older falcor-react-redux/container
HOC logic from Redux), which fetches a component's query and reduces over the resulting JSON until the query stabilizes. I haven't had time to properly document/blog about everything, but here's the general idea:
import { withFragment } from 'falcor-react-schema';
function MyList({ items = [] }) {
return <ul>{ items.map((item) => <MyListItem {...item}>) }</ul>
}
MyList = withFragment({
fragment: ({ items = [] }) => `{
items: {
length, [0...${items.length}]: {
whatever, item, keys, you, want
}
}`
})(MyList);
export { MyList }
from falcor.
Alright, super helpful--thanks.
If you request a range of integers along with the length, we can use the native Array methods on the JSON result
Ah, OK. I actually did have a length
property on my collection, however w/ boxValues()
enabled, so that length looks like {$type: "atom", value: 357, $size: 51}
rather than 357
, the map method does not work. (but I can confirm that when I disable boxValues, it does work as expected).
RE: falcor-react-schema
I haven't seen that published anywhere. Is it public? I have been looking at falcor-react-redux
, which looks like it's done a great job of abstracting over falcor and redux (a hard problem (for me, at least), given that falcor is asynchronous, and the redux store is synchronous). Reminds me of Relay a bit. Hadn't started running w/ it yet, as I'm still working on decoding it, but your above example gives a good hint at how it works. Any plans to publish docs?
from falcor.
Related Issues (14)
- iterate FalcorJSON instance HOT 3
- Connect Falcor model to react HOT 3
- Metadata is lost when returning sentinel from datasource HOT 3
- simultaneous requests against model w/ recycleJSON returns duplicate data HOT 3
- FalcorJSON $__status is 'resolved' when model progressively returns partial response from cache HOT 10
- Inconsistencies in Error reporting between recycleJSON true and false HOT 2
- Error in webpack "promise" module can not be found HOT 6
- Publish npm module without minification HOT 5
- Guard against setting _node property if given a path in #getBoundCacheNode() HOT 1
- Breaking api change regarding paths on getValue HOT 2
- A way to get an object without metadata? HOT 5
- falcor-router wrong path resolution. HOT 2
- falcor-react-redux: connected HOC does not receive parent props HOT 3
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 falcor.