从旧变体更新使用情况

云眼About 2 min

从旧变体更新使用情况

本主题介绍如何从旧变体的 Eyeofcloud Full Stack React SDK 进行更新。

代码示例

本节提供了代码示例,说明我们建议如何利用新的决策和事件跟踪 API。所有现有方法和实现仍包含在内并受支持,并且只有在弃用标记和未来主要变体后才会删除。

我们建议采用新的“决定”、“全部决定”和“跟踪事件”方法,作为当前在实现中使用 isFeatureEnabled、getFeatureVariable、getAllFeatures或Track 调用的更灵活、更易于使用的替代方法。

有关早期方法,请参阅 SDK 参考指南的早期变体open in new window

下面是如何将旧方法迁移到较新方法的一些示例。

React

// ------------------------------- // Eyeofcloud Feature // ------------------------------- // old method using Feature component function MyFeature() { return ( <EyeofcloudFeature feature="flag1"> {(isEnabled, variables) => <div>{isEnabled} - {variables}</div>} </EyeofcloudFeature> ); } // old method using Feature hook function MyFeature() { const [isEnabled, variables] = useFeature('flag1'); return <div>{isEnabled} - {variables}</div>; } // new method function MyFeature() { const [decision] = useDecision('flag1'); return <div>{decision.enabled} - {decision.variables}</div>; } // ------------------------------- // Eyeofcloud Experiment // ------------------------------- // old method using Experiment component function MyExperiment() { return ( <EyeofcloudExperiment experiment='experiment1'> <EyeofcloudVariation variation='firstvariation'> <div>First Variation</div> </EyeofcloudVariation> <EyeofcloudVariation variation='secondvariation'> <div>Second Variation</div> </EyeofcloudVariation> </EyeofcloudExperiment> ); } // old method using Experiment hook function MyExperiment() { const [variation] = useExperiment('experiment1'); return ( <> {variation === 'firstvariation' && <div>First Variation</div>} {variation === 'secondvariation' && <div>Second Variation</div>} </> ); } // new method function MyExperiment() { //decide hook uses flag key. New Api does not support flag-less experiments const [decision] = useDecision('flagfor_experiment1'); return ( <> {decision.variationKey === 'firstvariation' && <div>First Variation</div>} {decision.variationKey === 'secondvariation' && <div>Second Variation</div>} </> ); } // ------------------------------- // Track // ------------------------------ // unlike other SDKs, no change from old method (eyeofcloud_client.track)

激活方法和A / B测试

与现有的“已启用功能”方法一样,“决定”方法基于灰度发布(特性标帜)键,不支持独立的 A/B 测试或多臂 Bandit。我们正在努力长期统一应用程序的数据模型和接口,以减少维护多种不同访问方法的需求。同时,仍然可以在旧项目中使用“激活”和“获取变体”方法以及“决定”方法进行独立的 A/B 测试。

Last update:
Contributors: “zhangweixue”,zhangweixue