Coder Social home page Coder Social logo

fullstack-labs's Introduction

Optimizely FullStack Labs

A home for exciting up and coming Optimizely FullStack projects.

Packages

This repository is a monorepo that we manage using Lerna.

Package Status Version Description
js-web-sdk beta 3.0.0-beta3 Browser wrapper for Optimizely's Javascript SDK.
react-sdk beta 0.2.0-beta3 Use Optimizely Feature Flags and AB Tests easily in React with a library of pre-built components.
example-react-16 example -- A simple example using js-web-sdk and react-sdk in React 16
example-react-typescript example -- A simple example using js-web-sdk and react-sdk in React + TypeScript
example-react-15 example -- A simple example using js-web-sdk and react-sdk in React 15

Package Status Types

experimental - These APIs are still in the development stage. Usage of this in production is not recommended

beta - These packages are undergoing their final testing before a stable release. APIs will be generally stable, however they may change slightly before reaching stable.

stable - These packages have been vetted and used in production. APIs for this will be stable and semantic versioning followed for any API breaking changes.

example - These are packages that are small examples showing how to use the packages in this respository.

Contributing

Please see CONTRIBUTING

Development

Bootstrapping all packages

yarn
lerna bootstrap

Running an Example with local symlinks

  1. Ensure the package.json files are pointing the correct version as the local packages.

  2. lerna run build

  3. lerna link

  4. cd packages/example-react-typescript && yarn start

fullstack-labs's People

Contributors

hillaryfraley-optimizely avatar jordangarcia avatar mjc1283 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fullstack-labs's Issues

Exposing Context for App.contextType

For React SDK
Hello!
First of all, This is very useful! Thank you for making this available FullStack Labs!
I was wondering if you can expose the Context file for the package for me to reference it in contextType.

Instead of only using render prop strategy, this might also be useful!

If possible, I can also try adding this as a PR myself

logLevel is not honored by instance

For React SDK. logLevel is not honored when setting up the instance.

const optimizely = optimizelySDK.createInstance({
  sdkKey: OPTIMIZELY_SDK_KEY,
  // Log Level settings [0, 1, 2, 3, 4]
  // https://github.com/optimizely/node-sdk/blob/master/lib/utils/enums/index.js#L20-L26
  logLevel: 0
})

Still displays console logs when running.

State of child-components is not updated if OptimizelyProvider's props are changed.

There is no possibility to update datafile or userId of OptimizelyProvider.
Use cases: if user is logged in, datafile is changed.

const optimizelyRevision = 0;
class App extends Component {
    constructor(props) {
        super(props);
        this.state = {
            optimizely: null
        };
    }

    componentDidMount() {
        this.getOptimizelyData();
        //Check for updates each 5 min
        setInterval(this.getOptimizelyData, 5 * 60 * 1000);
    }

    getOptimizelyData = () => {
        fetch(optimizelyDatafileUrl).then(resp => resp.json()).then((optimizelyDatafile) => {
            const revision = parseInt(optimizelyDatafile.revision, 10);
            if (!Number.isNaN(revision) && revision > optimizelyRevision) {

                // Newer Datafile available!

                optimizelyRevision = revision;
                const optimizely = optimizelySDK.createInstance({
                    datafile: optimizelyDatafile,
                });

                this.setState({
                    optimizely
                });
            }
        });
    }

    onLogin = (userId) {
        this.setState({
            userId
        });
    }

    render () {
        const { optimizely, userId } = this.state;

        return optimizely && <OptimizelyProvider optimizely={optimizely} userId={userId}>
            <OptimizelyFeature feature="FEATURE_FLAG">
                {featureEnabled => (featureEnabled
                    ? <div>Enabled</div>
                    : <div>Disabled</div>
                )}
            </OptimizelyFeature>
        </OptimizelyProvider>
    }
}

According to https://docs.developers.optimizely.com/rollouts/docs/instantiate-a-client

 Any time you retrieve an updated datafile, just re-instantiate the same client.

I've re-instantiated client but value of featureEnabled is not changed.

imho, OptimizelyFeature (and other...) component should have something like that:

static getDerivedStateFromProps(nextProps, prevState) {
        const { feature, optimizely } = nextProps;
        let newState = null;

        if (prevState.optimizely !== optimizely) {
            const isEnabled = optimizely.isFeatureEnabled(feature);
            const variables = optimizely.getFeatureVariables(feature);
            newState = {
                canRender: true,
                isEnabled,
                variables,
                optimizely
            };
        }
        return newState;
    }

Unable to build typescript example

Attempted to follow the readme. Not sure if related to #27.

> cd packages/example-react-typescript
> npx lerna run build
npx: installed 669 in 31.302s
info cli using local version of lerna
lerna notice cli v3.4.3
lerna info Executing command in 2 packages: "yarn run build"
lerna ERR! yarn run build exited 1 in '@optimizely/react-sdk'
lerna ERR! yarn run build stdout:
yarn run v1.16.0
$ rm -rf dist/ && node ./scripts/build.js

Building ES modules...
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

lerna ERR! yarn run build stderr:
/bin/sh: ./node_modules/.bin/rollup: No such file or directory
child_process.js:656
    throw err;
    ^

Error: Command failed: ./node_modules/.bin/rollup -c scripts/config.js -f es -o dist/react-sdk.mjs
    at checkExecSyncError (child_process.js:616:11)
    at execSync (child_process.js:653:13)
    at exec (/Users/nope/git/fullstack-labs/packages/react-sdk/scripts/build.js:8:10)
    at Object.<anonymous> (/Users/nope/git/fullstack-labs/packages/react-sdk/scripts/build.js:19:1)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
error Command failed with exit code 1.

lerna ERR! yarn run build exited 1 in '@optimizely/react-sdk'
lerna WARN complete Waiting for 1 child process to exit. CTRL-C to exit immediately.

react-sdk latest tag points at previous release

The examples all point to the 0.3.0-beta1 release of react-sdk, but the dist-tags still list 0.2.0-beta1 as the latest version:

> yarn info @optimizely/react-sdk dist-tags
yarn info v1.12.1
{ latest:
   '0.2.0-beta1',
  beta:
   '0.3.0-beta1' }
Done in 0.88s.

Is this intentional?

Expected stable release date?

Is there a date when we can expect a stable version for the react sdk? I'd love to use this in a production project, but it would be nice to be assured that the api was stable first.

react-sdk - TypeError: optimizely.setUser is not a function

I came across this issue when trying to deploy my React app using the Rollouts wrapper.

TypeError: optimizely.setUser is not a function
new OptimizelyProvider
node_modules/@optimizely/react-sdk/dist/react-sdk.js:196

  193 | }
  194 | 
  195 | if (finalUser) {
> 196 |   optimizely.setUser(finalUser);
  197 | }
  198 | 
  199 | return _this;

Below is the main app with the wrapper. The app is deployed with the real sdkKey (not included below). We attempted to hard code the .setUser function, but to no avail. (commented out) The package.json file is included below. File structure below that.

Thanks for your help!

import React, { Component } from 'react';
import { Switch, Route, Link } from 'react-router-dom';
import { OptimizelyProvider, OptimizelyFeature } from '@optimizely/react-sdk';
import * as optimizelySDK from '@optimizely/optimizely-sdk';
import OptimizelyFullStack from './views/OptimizelyFullStack'

import Links from './views/Links';
import About from './views/About';
import Audience from './views/Audience';
import WheelWorks from './views/WheelWorks';
import Kb4 from './views/Kb4';
import NotFound from './views/NotFound';
import './App.css';
import { AwesomeButton } from "react-awesome-button";
import "react-awesome-button/dist/styles.css";
import 'react-awesome-button/dist/themes/theme-blue.css';

const optimizely = optimizelySDK.createInstance({
  sdkKey: '<my_key>',

})
// optimizely.setUser = () => {}
// optimizely.userId = {id: 'user 123'}

class App extends Component {
  render() {
    return (
      <OptimizelyProvider
          optimizely={optimizely}
          userId={'user123'}
          userAttributes={{
            'customerId': 123,
            'isVip': true,
          }}>
        <div>
          <OptimizelyFeature feature="secondary_icon">
          {(isEnabled) => (
            isEnabled
            ? (
            <div className="App">
              <AwesomeButton className="banner" type="secondary" style={{ height: '120px'}}> 
                  <Link to="/" style={{
                      textDecoration: 'none', 
                      fontSize: '300%' 
                  }}>Optimizely Experimental Knowledge Base ๐Ÿ’ก</Link>
              </AwesomeButton>
              <div id="container">
                  <p className="bannerSubText"> How to's, Routes and Rabbit Holes. . .</p>
              </div>
              <Switch>
                  <Route exact path="/" component={Links} />
                  <Route exact path="/about" component={About} />
                  <Route exact path="/OptimizelyFullStack" component={OptimizelyFullStack} />
                  <Route exact path="/audience" component={Audience} />
                  <Route exact path="/wheelWorks" component={WheelWorks} />
                  <Route exact path="/kb4" component={Kb4} />
                  <Route path="*" component={NotFound} />
              </Switch>
        </div>
            ) : (
            <div className="App">
              <AwesomeButton className="banner" type="primary" style={{ height: '120px'}}> 
                  <Link to="/" style={{
                      textDecoration: 'none', 
                      fontSize: '300%' 
                  }}>Optimizely Experimental Knowledge Base ๐Ÿ’ก</Link>
              </AwesomeButton>
              <div id="container">
                  <p className="bannerSubText"> How to's, Routes and Rabbit Holes. . .</p>
              </div>
              <Switch>
                  <Route exact path="/" component={Links} />
                  <Route exact path="/about" component={About} />
                  <Route exact path="/OptimizelyFullStack" component={OptimizelyFullStack} />
                  <Route exact path="/audience" component={Audience} />
                  <Route exact path="/wheelWorks" component={WheelWorks} />
                  <Route exact path="/kb4" component={Kb4} />
                  <Route path="*" component={NotFound} />
              </Switch>
            </div>
            )
          )}
          </OptimizelyFeature>
        </div>
      </OptimizelyProvider>
    );
  }
}


export default App;

package.json file:

{
  "name": "kb-proto-1",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@optimizely/react-sdk": "0.4.0-beta1",
    "react": "^16.9.0",
    "react-dom": "^16.9.0",
    "react-scripts": "3.1.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

file structure:
image

Additionally, I looked in the react-sdk.js file and noticed the code does not match the error:

node_modules/@optimizely/react-sdk/dist/react-sdk.js

193 |
194 |function withOptimizely(Component) {
195 |     var WithOptimizely = /** @class */ (function (_super) {
196 |         __extends(WithOptimizely, _super);
197 |         function WithOptimizely() {
198 |             return _super !== null && _super.apply(this, arguments) || this;
199 | }

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.