Closed andreyluiz closed 7 years ago
Which version of tectonic are you using?
The first version pollutes the top level manager. Namespace with drivers, IE. manager.fromSuperagent instead of manager.drivers.fromSuperagent in V2.
It's a minor change but it felt way better to have things organized like this.
Additionally, I love the way that you're producing endpoints and colocating them with the model itself. I'll dig into this error in a sec as your code looks correct
On Tue, Feb 14, 2017, 9:02 AM Andrey Luiz notifications@github.com wrote:
I have a very basic setup:
models/User.js
import { Model } from 'tectonic'; export default class User extends Model { static modelName = 'user';
static fields = { id: undefined, name: '', email: '', position: '', phone: '', password: '', createdAt: 0, updatedAt: 0, } } export const endpoints = [ { returns: User.getList(), meta: { url: '/api/users', }, }, ];
setupManager.js
import { Manager, BaseResolver } from 'tectonic';import TectonicSuperagent from 'tectonic-superagent';import { endpoints as userEndpoints } from './models/User'; export default (store) => { const manager = new Manager({ resolver: new BaseResolver(), drivers: { fromSuperagent: new TectonicSuperagent(), }, store, });
manager.drivers.fromSuperagent([ ...userEndpoints, ]);
return manager; };
Simple! However, the manager.drivers in setupManager is undefined. Then it show me an error: TypeError: Cannot read property 'fromSuperagent' of undefined.
I have looked in the manager variable and found out that there's a function called fromSuperagent. But nothing of drivers. Look:
Manager { cache: Cache { store: { dispatch: [Function], subscribe: [Function: subscribe], getState: [Function: getState], replaceReducer: [Function: replaceReducer] } }, store: { dispatch: [Function], subscribe: [Function: subscribe], getState: [Function: getState], replaceReducer: [Function: replaceReducer] }, resolver: BaseResolver { satisfiabilityChain: [ [Function: doesSourceSatisfyQueryParams], [Function: doesSourceSatisfyQueryModel], [Function: doesSourceSatisfyAllQueryFields], [Function: doesSourceSatisfyQueryReturnType], [Function: doesSourceSatisfyQueryType] ], queries: {}, queriesInFlight: {}, statusMap: {}, store: { dispatch: [Function], subscribe: [Function: subscribe], getState: [Function: getState], replaceReducer: [Function: replaceReducer] }, cache: Cache { store: [Object] } }, sources: Sources { definitions: Map {} }, fromSuperagent: [Function] }
I tried to call the function:
manager.fromSuperagent([...]);
But this also throws me an error Source definition must be comrpised of models, such as Model.list().
Am I doing something wrong?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/tonyhb/tectonic/issues/77, or mute the thread https://github.com/notifications/unsubscribe-auth/AASsAYtJO3edIEfqDPZXBVdQS0O3UUrVks5rcd4RgaJpZM4MAu4J .
v1.3.2.
Ah - if you upgrade to 2.0.2 things should work as expected in the docs
Wow! Okay. I saw the releases and the latest one is 1.3.2. :P
I'll upgrade it and reply in an instant.
Yeah, for some reason NPM doesn't respect semver in that list :(
About the endpoints, I'll use a bunch of CRUD tables in my application, so I need to modularize them somehow. That's the best idea I could produce. :P
The setup is right how I wrote earlier, but still I get Source definition must be comrpised of models, such as Model.list()
. Does this have problems with SSR?
Oh, I got it. I was using User.getList(), like in version 1.x. With User.list() it works perfectly. :)
Thank you for the help.
Ah yeah!! Seeing as that's so easy to miss I should make the error more descriptive:
.getList returns a query for a list of models. .list specifies that the source returns a list.
They're complimentary but used in different contexts.
Thanks for the heads up!
On Tue, Feb 14, 2017, 9:16 AM Andrey Luiz notifications@github.com wrote:
Closed #77 https://github.com/tonyhb/tectonic/issues/77.
— You are receiving this because you commented.
Reply to this email directly, view it on GitHub https://github.com/tonyhb/tectonic/issues/77#event-961744533, or mute the thread https://github.com/notifications/unsubscribe-auth/AASsAek9anR3mdXbSvQjzEpVUj8GDXduks5rceFtgaJpZM4MAu4J .
I have a very basic setup:
models/User.js
setupManager.js
Simple! However, the
manager.drivers
insetupManager
is undefined. Then it show me an error:TypeError: Cannot read property 'fromSuperagent' of undefined
.I have looked in the
manager
variable and found out that there's a function calledfromSuperagent
. But nothing ofdrivers
. Look:I tried to call the function:
But this also throws me an error
Source definition must be comrpised of models, such as Model.list()
.Am I doing something wrong?
EDIT I'm using v1.3.2.