Coder Social home page Coder Social logo

solid-utils's Introduction

solid-utils

A library with utilities to write Solid apps.

Requirements

Usage

Login

Initiate login with

SolidUtils.login()

This requires a popup.html file located at ./popup.html relative to the invoking app. See https://github.com/solid/solid-auth-client#building-the-popup on how to generate such a file.

The method returns a promise with the result of the login process.

Note: The SolidUtils.fetch() and SolidUtils.rdfFetch() will initiate the login process when needed. So you may not need to explicitely invoke SolidUtils.login().

You can set a function executed after successful login as follows:

SolidUtils.postLoginAction = function(loginResult) {
    //do something useful
    return loginResult;
}; 

This function is executed after each successful login, independently if login() is invoked explicitely or if the login process was initiated by a fetch-operation. Such a function is typically used to keep an area displaying information about the current user up to date.

Fetching data

The SolidUtils.fetch() method is a replacement for the standard fetch method that takes care of sending the authorization tokens and initiating the login process when needed.

The SolidUtils.rdfFetch() method will parse an RDF response and provide and add a property graph to the response object.

Example usage:

SolidAuthClient.currentSession().then(function (session) {
    if (session) {
        var user = $rdf.sym(session.webId);
        SolidUtils.rdfFetch(session.webId).then(function (response) {
            var name = response.graph.any(user, SolidUtils.vocab.foaf('name'));
            console.log("Hello "+name);
        }
    }
}       

Working with LDPCs

LDPCs is the Linked Data Platform equivalent of folders.

Create an LDPC with SolidUtils.createLdpc(base, name), if your not sure if the LDPC you need already exist, or when you want to create parent LDPCs as well use SolidUtils.createPath(base, path), basemust point to an existing LDPC, but path can contain slashes expressing a hierarchy (e.g. path/to/my/new/ldpc.

Example usage:

//returns a promise for the LDPC where we publish our data
function appDataDir() {
    return SolidUtils.getStorageRootContainer().then(function (root) {
                return SolidUtils.createPath(root.value + "public","where/my/app/publishes/data");
    }
}

solid-utils's People

Contributors

alemela avatar bobwalsh avatar nleanba avatar retog avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.