These are chat archives for canjs/canjs

21st
Jul 2017
AntonProkofyev
@AntonProkofyev
Jul 21 2017 13:21

Hi guys

const AppViewModel = DefineMap.extend({
    currentUser: { 
        get(last, resolve) {
            personConnection.get({ id: 'someId' }).then(resolve);
        }
})

this is vm which use can connect to get current user data
how can i force it to get the data without adding something like {{currentUser}} in component template.
it will be perfect if it try to get data when i create new AppViewModel ({})

Kevin Phillips
@phillipskevin
Jul 21 2017 13:28
you can add an init() that sets up a binding on currentUser
why do you want to do that exactly?
AntonProkofyev
@AntonProkofyev
Jul 21 2017 13:34
i need to know this information to modify another props in AppViewModel
the simle example if connect returns {firstName:'firstName', lastName:'lastName'} i would like to have
fullName : {
get() {return this.currentUser.firstName + this.currentUser.lastName}
}
Kevin Phillips
@phillipskevin
Jul 21 2017 13:40
so just doing that should cause your get() call
since fullName is binding on currentUser
AntonProkofyev
@AntonProkofyev
Jul 21 2017 13:41
hmmmm
Kevin Phillips
@phillipskevin
Jul 21 2017 13:42
it just might not be as fast as you need, so you probably need to do
fullName : {
  get() {
    if (this.currentUser) {
      return this.currentUser.firstName + this.currentUser.lastName;
    }
  }
}
AntonProkofyev
@AntonProkofyev
Jul 21 2017 13:42
mmmm ok will try this, thx
AntonProkofyev
@AntonProkofyev
Jul 21 2017 13:50
yep it's working thx Kevin
Kevin Phillips
@phillipskevin
Jul 21 2017 13:58
:smile:
Pedro Mendes
@pmgmendes
Jul 21 2017 19:39
Hey guys, I was just starting to watch Donejs contributors meeting from this week and it seems to have the same static image with Chasen's desktop throughout the video... is it suppose to be like that?
Mohamed Cherif Bouchelaghem
@cherifGsoul
Jul 21 2017 19:40
@pmgmendes No I think you should see Chasen's shared screen
Chasen Le Hara
@chasenlehara
Jul 21 2017 19:44
@pmgmendes I just checked the video and it seems correct (it’s not my desktop throughout)
Mohamed Cherif Bouchelaghem
@cherifGsoul
Jul 21 2017 19:45
@chasenlehara in the live it happened to me I saw only DoneJS logo but the record is correct
Pedro Mendes
@pmgmendes
Jul 21 2017 19:58
I've re-checked and it seems ok. Maybe some temp issue with the youtube app. I was only getting the audio. Thanks anyway.
9
Frank Lemanschik
@frank-dspeed
Jul 21 2017 20:46
the video is well
just wrapping it up
:D
Frank Lemanschik
@frank-dspeed
Jul 21 2017 20:51
can some one tell me where chris repo is
i can't understand him :)
rage?
rache?
Chasen Le Hara
@chasenlehara
Jul 21 2017 20:52
Frank Lemanschik
@frank-dspeed
Jul 21 2017 20:53
ah Raj
lol
i never tought about that alternativ :D
@chasenlehara thanks
Chasen Le Hara
@chasenlehara
Jul 21 2017 20:54
👍
Frank Lemanschik
@frank-dspeed
Jul 21 2017 21:01
@pYr0x wasn't service worker for doing computation? and push in and out results? i think its not for cashing
Chasen Le Hara
@chasenlehara
Jul 21 2017 21:02
Web workers are handy for computation; service workers are good for fetching/caching.
Frank Lemanschik
@frank-dspeed
Jul 21 2017 21:03
ah mixed that up probally
Chasen Le Hara
@chasenlehara
Jul 21 2017 21:03
All the worker terminology 😂
Frank Lemanschik
@frank-dspeed
Jul 21 2017 21:03
yes web and service i understand
but i wonder why this should be better then all the other methods like local-storage
that exist
current browsers have a lot of existing functionality where you can store data like responses to cache them
but maybe service workers are only in memory
need to look into that
Kevin Phillips
@phillipskevin
Jul 21 2017 22:09
it can cache resources, not just data
Frank Lemanschik
@frank-dspeed
Jul 21 2017 22:10
what means that
Kevin Phillips
@phillipskevin
Jul 21 2017 22:10
like... javascript files or images
Frank Lemanschik
@frank-dspeed
Jul 21 2017 22:10
for me there is only data any service is a resource
thats also data
for example store images as base64 string
for me thats all data all has a ascii or binary representation
but its not moving in it
so it don't gets computed or created
so its stale data
no diffrence to any other object storage
I really don't get the diffrence i only know existing data and data that gets created for example from existing values via a computation
maybe service workers are more performant but the browsers already got a hugh system for storage like databases and all that
I'm not an expert on it, but you can read up on it if you want
Frank Lemanschik
@frank-dspeed
Jul 21 2017 22:15
ok readed it up
i still don't get whats new
:D
i know tons of existing tech for exact the same thing
and i know them since many years and all are using them since many years but ok
i think there is simply a need for new stuff to get the industrie going
but no inovation :(
having 2 cached versions isn't new also
even the cheapest php cms's like joomla wordpress or drupal offer that
via simply putting version information in the url via ?version=9342
Mohamed Cherif Bouchelaghem
@cherifGsoul
Jul 21 2017 22:18
@frank-dspeed actualy is more then that even in "cheapest PHP cms's"
Frank Lemanschik
@frank-dspeed
Jul 21 2017 22:18
maybe the performance is better but can't imagin how that should be more performant for me it looks like a pre coded cache lib like they exist for many years
sure there is more in the cms systems :)
but i only want to get why they implament that in browsers
if they already got so many data storage methods
and its up to the developer what to cache and return
even with this method
Kevin Phillips
@phillipskevin
Jul 21 2017 22:19
how would you cache your main js file?
Frank Lemanschik
@frank-dspeed
Jul 21 2017 22:20
how big is it?
Kevin Phillips
@phillipskevin
Jul 21 2017 22:20
why does that matter?
what code would run to load it from the cache?
Frank Lemanschik
@frank-dspeed
Jul 21 2017 22:20
the diffrent browser storage places
have diffrent limits
client side javascript would load it
Kevin Phillips
@phillipskevin
Jul 21 2017 22:20
that's what I'm asking
Frank Lemanschik
@frank-dspeed
Jul 21 2017 22:20
i would drop my html with just the loader
it does the rest
Kevin Phillips
@phillipskevin
Jul 21 2017 22:20
how would you cache the client side javascript
with service worker... your html page has a script tag, the service worker intercepts it, and returns the cached version
Frank Lemanschik
@frank-dspeed
Jul 21 2017 22:21
i would let the browser do it once
Kevin Phillips
@phillipskevin
Jul 21 2017 22:21
so your app works offline
Frank Lemanschik
@frank-dspeed
Jul 21 2017 22:21
then my loader fetches the rest
Kevin Phillips
@phillipskevin
Jul 21 2017 22:21
how? your loader is cached
you're offline
can't load it
Frank Lemanschik
@frank-dspeed
Jul 21 2017 22:21
it must be already loaded once
like this service worker
Kevin Phillips
@phillipskevin
Jul 21 2017 22:21
right
Frank Lemanschik
@frank-dspeed
Jul 21 2017 22:21
so its the same
anything needs to be transfered once
thats logical
Kevin Phillips
@phillipskevin
Jul 21 2017 22:22
no, in your solution, you have to have javascript to handle loading it from the cache
Frank Lemanschik
@frank-dspeed
Jul 21 2017 22:22
and with service workers? i think they will not fly into my browser
Kevin Phillips
@phillipskevin
Jul 21 2017 22:22
you have to be online the first time, but subsequent times you an be totally offline
Frank Lemanschik
@frank-dspeed
Jul 21 2017 22:22
yes
Kevin Phillips
@phillipskevin
Jul 21 2017 22:22
and the service worker is running in the background
Frank Lemanschik
@frank-dspeed
Jul 21 2017 22:23
same with my loader
it needs to load only once
browser cache does that already
you visit the url one time online
then you can use that offline also
look into your chrome dev tools for example
under Application
there you find the diffrent storage methods also service workers
but it makes no diffrence application cache does the same
local storage also
IndexDB can store some data
and web sql also
you can load whole websites from the internal browser cache
as this saves files to disk
you can watch your cache directory of the browser the newer once now compress all that stuff
but befor 10 years or even a shorter time they saved the .html .js files directly in clear formart
now for example chrome uses his own db formart but in that file is all clear text
Frank Lemanschik
@frank-dspeed
Jul 21 2017 22:29

Type chrome://cache in the address bar to get a list of resources cached by Chrome.

Unfortunately, clicking on a resource shows a HEX+ASCII preview of its contents. In cases when the content is gzipped (archived) this preview cannot be read, unless processed with a tool that can decompress it.

(function() {
    var preTags = document.getElementsByTagName('pre');
    var preWithHeaderInfo = preTags[0];
    var preWithContent = preTags[2];

    var lines = preWithContent.textContent.split('\n');

    // get data about the formatting (changes between different versions of chrome)
    var rgx = /^(0{8}:\s+)([0-9a-f]{2}\s+)[0-9a-f]{2}/m;
    var match = rgx.exec(lines[0]);

    var text = '';
    for (var i = 0; i < lines.length; i++) {
        var line = lines[i];
        var firstIndex = match[1].length; // first index of the chars to match (e.g. where a '84' would start)
        var indexJump = match[2].length; // how much space is between each set of numbers
        var totalCharsPerLine = 16;
        index = firstIndex;
        for (var j = 0; j < totalCharsPerLine; j++) {
            var hexValAsStr = line.substr(index, 2);
            if (hexValAsStr == '  ') {
                // no more chars
                break;
            }

            var asciiVal = parseInt(hexValAsStr, 16);
            text += String.fromCharCode(asciiVal);

            index += indexJump;
        }
    }

    var headerText = preWithHeaderInfo.textContent;
    var elToInsertBefore = document.body.childNodes[0];
    var insertedDiv = document.createElement("div");
    document.body.insertBefore(insertedDiv, elToInsertBefore);

    // find the filename
    var nodes = [document.body];
    var filepath = '';
    while (true) {
        var node = nodes.pop();
        if (node.hasChildNodes()) {
            var children = node.childNodes;
            for (var i = children.length - 1; i >= 0; i--) {
                nodes.push(children[i]);
            }
        }

        if (node.nodeType === Node.TEXT_NODE && /\S/.test(node.nodeValue)) {
            // 1st depth-first text node (with non-whitespace chars) found
            filepath = node.nodeValue;
            break;
        }
    }

    outputResults(insertedDiv, convertToBase64(text), filepath, headerText);

    insertedDiv.appendChild(document.createElement('hr'));

    function outputResults(parentElement, fileContents, fileUrl, headerText) {
        // last updated 1/27/12
        var rgx = /.+\/([^\/]+)/;
        var filename = rgx.exec(fileUrl)[1];

        // get the content type
        rgx = /content-type: (.+)/i;
        var match = rgx.exec(headerText);
        var contentTypeFound = match != null;
        var contentType = "text/plain";
        if (contentTypeFound) {
            contentType = match[1];
        }

        var dataUri = "data:" + contentType + ";base64," + fileContents;

        // check for gzipped file
        var gZipRgx = /content-encoding: gzip/i;
        if (gZipRgx.test(headerText)) {
            filename += '.gz';
        }

        // check for image
        var imageRgx = /image/i;
        var isImage = imageRgx.test(contentType);

        // create link
        var aTag = document.createElement('a');
        aTag.textContent = "Left-click to download the cached file";
        aTag.setAttribute('href', dataUri);
        aTag.setAttribute('download', filename);
        parentElement.appendChild(aTag);
        parentElement.appendChild(document.createElement('br'));

        // create image
        if (isImage) {
            var imgTag = document.createElement('img');
            imgTag.setAttribute("src", dataUri);
            parentElement.appendChild(imgTag);
            parentElement.appendChild(document.createElement('br'));
        }

        // create warning
        if (!contentTypeFound) {
            var pTag = document.createElement('p');
            pTag.textContent = "WARNING: the type of file was not found in the headers... defaulting to text file.";
            parentElement.appendChild(pTag);
        }
    }

    function getBase64Char(base64Value) {
        if (base64Value < 0) {
            throw "Invalid number: " + base64Value;
        } else if (base64Value <= 25) {
            // A-Z
            return String.fromCharCode(base64Value + "A".charCodeAt(0));
        } else if (base64Va
this is a javascript not complet because the limits in this chat
that would load and unzip the archived browser cache
@phillipskevin but i understand this allows to create a more easy url based cache
:D
thanks for your information so offline applications get made easyer
i am wondering why they call that service workers they should call it offline use able url based cache
Frank Lemanschik
@frank-dspeed
Jul 21 2017 22:35
like chrome://flags/#show-saved-copy
chrome://flags/#show-saved-copy <- paste that in your browser bar then you can setup that it will then show that button for the configured pages
and allow offline use of any page
Show Saved Copy Button Mac, Windows, Linux, Chrome OS, Android
When a page fails to load, if a stale copy of the page exists in the browser cache, a button will be presented to allow the user to load that stale copy. The primary enabling choice puts the button in the most salient position on the error page; the secondary enabling choice puts it secondary to the reload button. #show-saved-copy
you can test it simply run a donejs app local and then turn of the done serve and revisit the url i would advice you to modify /etc/hosts first so it has a uniq nice url
Frank Lemanschik
@frank-dspeed
Jul 21 2017 22:40
like 127.0.0.1 iam.kevin
then visit iam.kevin:3030
chrome://flags/#enable-offline-auto-reload <- this is also interristing with the show-saved-copy option
for updating when you go online again
Frank Lemanschik
@frank-dspeed
Jul 21 2017 22:46
firefox and so on have the same abilitys by the way
oh and ofcourse Use DevTools to emulate different network conditions. ... evaluate your site''s performance using the Chrome DevTools network emulator. ... your site on a variety of network connections, including Edge, 3G, and even offline.
if that don't works to turn of the done serve you need to use dev tools and turn that offline
sorry old version
current versions
@matthewp the google links above for network performance are maybe also interristing for you
and of course for you @phillipskevin because of the stache performance stuff