Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 15:14
    greenkeeper[bot] commented #5375
  • 15:14

    greenkeeper[bot] on core-js-3.3.1

    chore(package): update core-js … (compare)

  • 14:49
    greenkeeper[bot] labeled #5375
  • 14:49
    greenkeeper[bot] opened #5375
  • 14:49

    greenkeeper[bot] on core-js-3.3.0

    chore(package): update core-js … (compare)

  • Oct 12 18:35
    matthewp commented #5358
  • Oct 12 18:15
    chasenlehara commented #5358
  • Oct 12 06:41

    greenkeeper[bot] on @octokit

    (compare)

  • Oct 12 06:39

    greenkeeper[bot] on @octokit

    chore(package): update @octokit… (compare)

  • Oct 11 19:01
    m-mujica edited #5374
  • Oct 11 19:01
    m-mujica opened #5374
  • Oct 11 19:00

    m-mujica on update-deep-observable

    Update can-deep-observable to l… (compare)

  • Oct 11 18:55
    m-mujica edited #5365
  • Oct 11 18:54
    greenkeeper[bot] labeled #5373
  • Oct 11 18:54
    greenkeeper[bot] opened #5373
  • Oct 11 18:54

    greenkeeper[bot] on can-deep-observable-1.0.1

    fix(package): update can-deep-o… (compare)

  • Oct 11 16:42
    LakshanKarunathilake starred canjs/canjs
  • Oct 11 14:58
    greenkeeper[bot] labeled #5372
  • Oct 11 14:58
    greenkeeper[bot] opened #5372
  • Oct 11 14:58

    greenkeeper[bot] on can-observable-mixin-1.0.1

    fix(package): update can-observ… (compare)

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
this will get updated on the screen
so DefineMap is simply a eventEmitter
and emits events on get and set to stache
:D
hope that makes sense
for example you can make a value that returns a setInterval that sets a value on the viewModel like this.myVal = 2+x
then this will get reflected if you bind myVal
in stache
this way you can make nice count downs by the way
:D
Frank Lemanschik
@frank-dspeed
so remember your view should always get updated via the viewModel it self without a connection
the connection is only to add stuff from outside like a server or other eventEmitter