Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 16:23
    phillipskevin closed #4841
  • Oct 15 21:43

    phillipskevin on master

    Update dist for release (compare)

  • Oct 15 21:43

    phillipskevin on v6.1.1

    Update dist for release 6.1.1 (compare)

  • Oct 15 21:34

    phillipskevin on can-observable-mixin-1.0.2

    (compare)

  • Oct 15 21:34

    phillipskevin on master

    fix(package): update can-observ… Merge branch 'master' into gree… Merge pull request #5382 from c… (compare)

  • Oct 15 21:34
    phillipskevin closed #5382
  • Oct 15 21:34

    phillipskevin on can-make-map-1.2.2

    (compare)

  • Oct 15 21:34

    phillipskevin on master

    fix(package): update can-make-m… Merge pull request #5380 from c… (compare)

  • Oct 15 21:34
    phillipskevin closed #5380
  • Oct 15 20:30
    phillipskevin synchronize #5382
  • Oct 15 20:30

    phillipskevin on can-observable-mixin-1.0.2

    fix(package): update can-observ… fix(package): update can-simple… Merge pull request #5372 from c… and 2 more (compare)

  • Oct 15 20:30
    phillipskevin opened #5382
  • Oct 15 20:28

    phillipskevin on can-simple-map-4.3.3

    (compare)

  • Oct 15 20:28

    phillipskevin on master

    fix(package): update can-simple… Merge pull request #5378 from c… (compare)

  • Oct 15 20:28
    phillipskevin closed #5378
  • Oct 15 20:26

    phillipskevin on can-observable-mixin-1.0.1

    (compare)

  • Oct 15 20:26

    phillipskevin on master

    fix(package): update can-observ… Merge pull request #5372 from c… (compare)

  • Oct 15 20:26
    phillipskevin closed #5372
  • Oct 15 20:25

    phillipskevin on update-make-map

    (compare)

  • Oct 15 20:25
    phillipskevin closed #5381
Nico R.
@nriesco
thanks @phillipskevin it looks like that plus https://canjs.com/doc/can-define.types.html will help me understand (also thanks @jeroencornelissen !)
Kevin Phillips
@phillipskevin
there's also https://www.youtube.com/watch?v=eXp3m-ZlL4Y if you prefer a video
Justin Meyer
@justinbmeyer
Justin Meyer
@justinbmeyer
actually, it will be here: https://www.youtube.com/watch?v=R4F_U_BwwWM
Frank Lemanschik
@frank-dspeed
I need a new Job i think
Viktor Busko
@Lighttree

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.

Frank Lemanschik
@frank-dspeed
hmmm there was a example for that
i think todoMVC
that adds todo on top
Viktor Busko
@Lighttree
let me check
Frank Lemanschik
@frank-dspeed
but i am wondering why you tigger realtime behavier in a save function=?
shouldn't that be called from a event system?
Viktor Busko
@Lighttree
mmm...
Frank Lemanschik
@frank-dspeed
like socket.io
i mean this should get called with entity even if thats created else where and not only in your frontend or i am wrong?
or even if this is not a distributed system you should maybe tigger it from a event emitter i think
did you know that a canDefineMap is a eventEmitter?
Viktor Busko
@Lighttree
Give me a min to think about :)
Frank Lemanschik
@frank-dspeed
ya sure all no problem i understand that this is much to learn and understand :)
Viktor Busko
@Lighttree

I just based my solution on this example:

https://canjs.com/doc/can-connect/real-time/real-time.createInstance.html

as I got we have to call this createInstance right after our connection saved the instance. In my case this is not socket.io but normal ajax call based on url behavior.

or even if this is not a distributed system you should maybe trigger it from a event emitter i think
not sure that I understand the way how this should be organized.

did you know that a canDefineMap is a eventEmitter?
I know that we can call something like map.dispatch('customEvent', [data]), but not sure that I understand how this should improve the case.

Frank Lemanschik
@frank-dspeed
then i don't understand why you need to use createInstance at all
its for getting called external
Viktor Busko
@Lighttree
Mmmm this updates UI on the fly :)
so I just make save and UI updates with the new item in the list )
Frank Lemanschik
@frank-dspeed
your case looks more like return new Entity(entity)
is what you want
it sounds like you designed something wrong :)
ah UI updates
i understand the normal way for this is diffrent i think but overall when it works let it work
but in general the ui should simply update when a value changes
because defineMaps are event emitters that dispatch events
create instance is a bridge
when a creation happens outside the ViewModel of the object
for example if you write a function that polls a server for changes
it can call this to add instances from server
but its not needed if your work in your frontend only
Viktor Busko
@Lighttree

MMmmm ok I'll try to clarify the case, because I showed you just one function :)

I have 1 component that renders list of entitiy
I have another component that adds new items in this list. But this is separate component, so I have to make "something" to update the list in another component.
And real-time with createInstance do the work :) Well...not sure that this is correct way.

I had no expectations that entity adder component will update list in another component, because it knows nothing about it. It just makes POST request using connection
But maybe I'm missing something...not sure
Frank Lemanschik
@frank-dspeed
Entity Model
should have Entity.list
a instance store most time made via canDefineList
so when ever you create a Entity with some values it adds that instance to its Enitity.list i think
:D
i think this is used in all guides look at it
Viktor Busko
@Lighttree

yes I have entity model like this:

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 realTime from 'can-connect/real-time/real-time';
import constructor from 'can-connect/constructor/constructor';
import constructorStore from 'can-connect/constructor/store/store';
import canMap from 'can-connect/can/map/map';
import memoryCache from 'can-connect/data/memory-cache/memory-cache';
import authBehavior from './authBehavior';
import Person from './person.model';
import fallThroughCache from './fall-through-cache-custom';

const cacheConnection = connect([
    memoryCache
], {
    name: 'entity'
});

const entity = DefineMap.extend({
    activityType: 'string',
    clientId: 'number',
    id: 'number',
    creatorId: 'number',
    message: 'string',
    created: 'number',
    managerId: 'number',
    employeeId: 'number',
    externalId: 'number',
    readEmployee: 'boolean',
    readManager: 'boolean',
    title: 'string'

});

const algebra = new set.Algebra(
    set.props.id('id')
);

entity.List = DefineList.extend({
    '#': entity
});

entity.connection = connect(
    [realTime, authBehavior, parse, fallThroughCache, constructor, constructorStore, canMap], {
        url: 'v1/entity',
        Map: entity,
        List: entity.List,
        name: 'entity',
        parseListData(response) {
            return { data: response };
        },
        parseInstanceData(responseData) {
            return responseData.entityVO;
        },
        algebra,
        cacheConnection
    });

export default entity;

But it didn't refreshed UI untill I refresh the page.. so I was thinking that real-time is something that I have to use. But now I'm confused and not sure :D

Frank Lemanschik
@frank-dspeed
there it is List
no the list gets updated by getter and setter most time
you bind a value in stache to a getter setter
and when ever something changes