cherifGsoul on document-inserted-removed-can6
Update after review (compare)
cherifGsoul on theme-3.0.0-pre.5
cherifGsoul on master
Update bit-doc-html-canjs (#544… (compare)
cherifGsoul on theme-3.0.0-pre.5
Update bit-doc-html-canjs Upda… (compare)
cherifGsoul on update-api-page
cherifGsoul on master
Update API page (#5432) * Upda… (compare)
greenkeeper[bot] on core-js-3.5.0
chore(package): update core-js … (compare)
greenkeeper[bot] on can-observable-mixin-1.0.7
fix(package): update can-observ… (compare)
cherifGsoul on update-infrastructure-page
cherifGsoul on master
Update infrastructure page with… (compare)
Hi guys, I have one question regarding can-connect
. I have following model:
import DefineMap from 'can-define/map/map';
import DefineList from 'can-define/list/list';
import set from 'can-set';
import connect from 'can-connect';
import parse from 'can-connect/data/parse/parse';
import constructor from 'can-connect/constructor/constructor';
import canMap from 'can-connect/can/map/map';
import fallThroughCache from 'can-connect/fall-through-cache/fall-through-cache';
import constructorStore from 'can-connect/constructor/store/store';
import memoryCache from 'can-connect/data/localstorage-cache/localstorage-cache';
import realTime from 'can-connect/real-time/real-time';
import authBehavior from './authBehavior';
// Connection behaviors list
const behaviors = [realTime, authBehavior, fallThroughCache, constructorStore, parse, constructor, canMap];
const cacheConnection = connect([
memoryCache
], {
name: 'entity'
});
const Entity= DefineMap.extend({
id: 'number',
creatorId: 'number',
message: 'string',
title: 'string',
});
const algebra = new set.Algebra(
set.props.id('id')
);
Entity.List = DefineList.extend({
'#': Entity
});
Entity.connection = connect(
behaviors, {
url: '/api/v1/entity',
Map: Entity,
List: Entity.List,
name: 'entity',
parseInstanceData(responseData) {
return responseData.checkinVO;
},
algebra,
cacheConnection
});
export default Entity;
I have list of entities
on the page:
export const ViewModel = DefineMap.extend({
entityListPromise: {
get() {
return Entity.getList({});
}
},
entityList: {
Type: [Entity],
get(lastSet, resolve) {
this.entityListPromise.then(resolve);
}
}
});
I need to add new item to sever and expecting that this list will be updated automatically by:
this.entity.save()
but it seems that it doesn't work :( I can see new item in the list only after page refresh.
I've tried this as well:
this.entity.save().then((response) => {
Entity.connection.createInstance(response);
});
But didn't succeed as well.
Is it expected that can.js
will update list automatically or I have to push this item into list by myself ?
Hi everyone, could someone help with the next question:
I'm using can.connection with these behaviors: url, constructor, canMap and getting the list of instances using getList():
[{priorityId: 1, description: 'some text'}, {priorityId: 2, description}, ....] .
When I call .save() as a POST request it works fine, but when I try to UPDATE information of this instance my URL is wrong and becomes just like localhost:3000/. As I understood canjs expects to see ID in the list of instance props instead of priorityId.
How I can parse the response of getList() and replace priorityId field on id? Does can.Algebra help with it? Thanks in advance!
BTW, when I use this algebra:
const algebra = new set.Algebra(
set.props.id('priorityId')
);
My .get() request looks wrong: localhost:3000/?id=283, but without Algebra it looked fine: https://localhost:3000/priorities/283
route.data.should.deep.equal(routeTestObject);
AssertionError: expected { Object (page, flow) } to deeply equal { Object (page, flow) }
Maybe someone have an idea:
I'm trying to dynamically update UI when save something to data base using real-time
behavior.
When I use fixture with data and call my list like:
entityListPromise: {
get() {
return Entity.getList({});
}
},
All works fine and when I save items like:
save() {
this.entity.save().then((entity) => {
Entity.connection.createInstance(entity);
this.close();
});
},
UI updates automatically.
But as soon as I disable fixture and do the call with real get params that I need:
entityListPromise: {
get() {
return Entity.getList({
employeeId: this.owner.id,
startDate: new Date(2017, 1, 1).getTime(),
endDate: Date.now(),
limit: 1000
});
}
},
It doesn't work. As I got these params somehow broke this...
I'm really confused when declaring observables/variables within a defineMap. I think this is probably a basic topic, but I don't know how it really works.
I've seen (so far) the following syntaxes:
export const ViewModel = DefineMap.extend({
var1: { type: String, value: 'super' },
var2: { type: 'string', value: 'super' },
var3: { value: 'hello', serialize: false},
var4: 'string',
var5: 'any',
var6: '*',
})
I don't really know their differences and when to use them. As for the serialize option does it mean that ViewModel.serialize()
would return everything except from attributes with serialize: false
option?
Thanks
.serialize()
doesn’t return serialize: false
properties. I see them as “private” properties.var1
is incorrect and should be Type with a capital T: Type: String
or Type: MyCustomMap
var5
& var6
are identical, it means that your var can be anything. If you pass an object to type: ‘*’
it stays an object and isn’t converted to a DefineMap.
Guys correct me if I'm wrong. I need to add items to the list, and on UI it should appear at the top of the list (currently it adds to bottom and this is expected).
I'm using real-time
behavior so can.js
understands when to add by itself:
save() {
this.entity.save((entity) => {
Entity.connection.createInstance(entity);
});
},
What the correct way to tell it to add to very top of the list ? custom sort function in component when my list changes ?
There is also https://canjs.com/doc/can-set.props.sort.html but not sure that my case is correct for this, because as I got this designed to understand where we need to insert item, but I know this.